package com.newviews.tcmip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newviews.tcmip.common.constant.CombinConsts;
import com.newviews.tcmip.common.constant.CommonConsts;
import com.newviews.tcmip.common.enums.UiElCodeEnums;
import com.newviews.tcmip.common.model.PageModel;
import com.newviews.tcmip.common.model.ResultModel;
import com.newviews.tcmip.common.utils.RedisUtils;
import com.newviews.tcmip.common.utils.StringUtils;
import com.newviews.tcmip.common.utils.UUIDGenerator;
import com.newviews.tcmip.dao.EtcmDiseaseMapper;
import com.newviews.tcmip.dao.EtcmPxExMapper;
import com.newviews.tcmip.pojo.po.*;
import com.newviews.tcmip.dao.EtcmPxMapper;
import com.newviews.tcmip.pojo.vo.EtcmCommonBaseInfoRespVO;
import com.newviews.tcmip.pojo.vo.index.EtcmIndexStatusticsRespVO;
import com.newviews.tcmip.service.inf.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.newviews.tcmip.web.vo.combin.*;
import com.newviews.tcmip.web.vo.etcmherb.HerbIngrVo;
import com.newviews.tcmip.web.vo.etcmpx.EtcmStatisticsRespVo;
import com.newviews.tcmip.web.vo.etcmpx.PxDiseaseRespVo;
import com.newviews.tcmip.web.vo.etcmpx.PxIngrStatisticsRespVo;
import com.newviews.tcmip.web.vo.etcmpx.PxNetworkStatisticsRespVo;
import com.newviews.tcmip.web.vo.etcmpx.network.Relations;
import com.newviews.tcmip.web.vo.etcmpx.network.RelationsName;
import com.newviews.tcmip.web.vo.etcmpx.network.ResolutionNames;
import com.newviews.tcmip.web.vo.etcmpx.network.ScatterDiagram;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.io.PrintStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 处方基本信息库 服务实现类
 * </p>
 *
 * @author lxc
 * @since 2024-02-29
 */
@Service
public class EtcmPxServiceImpl extends ServiceImpl<EtcmPxMapper, EtcmPxPo> implements EtcmPxServiceInf {
    @Autowired
    private EtcmPxExServiceInf etcmPxExService;

    @Autowired
    private EtcmPxExMapper etcmPxExMapper;

    @Autowired
    private EtcmPxHerbServiceInf etcmPxHerbService;

    @Autowired
    private EtcmIngrExServiceInf etcmIngrExService;

    @Autowired
    private EtcmTargetExServiceInf etcmTargetExService;

    @Autowired
    private EtcmExperimentalRecordsExServiceInf etcmExperimentalRecordsExService;

    @Autowired
    private EtcmHerbServiceInf etcmHerbService;

    @Autowired
    private EtcmIngrServiceInf etcmIngrService;

    @Autowired
    private EtcmDiseaseServiceInf etcmDiseaseService;

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private EtcmDiseaseMapper etcmDiseaseMapper;

    @Override
    public ResultModel<PageModel<Map<String, String>>> search(String searchType, String content,String langCode) {
        //填充内容
        String fillInContent="";
        //默认分页
        int pageNo=1,pageSize=10;
        String uiCode;
        if(searchType.equals(CommonConsts.SEARCH_TYPE_1)){
            //处方数据
            uiCode= UiElCodeEnums.PRESCRIPTION.getUiElCode();
            return this.getPage(fillInContent, fillInContent, content, langCode, uiCode, pageNo, pageSize, fillInContent);
        }else if(searchType.equals(CommonConsts.SEARCH_TYPE_2)){
            //草药数据
            uiCode=UiElCodeEnums.HERB.getUiElCode();
            return etcmHerbService.getPage(langCode, uiCode, pageNo, pageSize, content, fillInContent, fillInContent, fillInContent, fillInContent);
        }else if(searchType.equals(CommonConsts.SEARCH_TYPE_3)){
            //成分数据
            uiCode=UiElCodeEnums.INGR.getUiElCode();
            return etcmIngrService.getPage(langCode, uiCode, pageNo, pageSize, content, fillInContent,fillInContent);
        }else if(searchType.equals(CommonConsts.SEARCH_TYPE_4)){
            //疾病数据
            uiCode=UiElCodeEnums.DISEASE.getUiElCode();
            return etcmDiseaseService.getPage(content, langCode, uiCode, pageNo, pageSize, fillInContent,fillInContent);
        }else {
            return new ResultModel<PageModel<Map<String, String>>>().failure("传递搜索类型参数错误");
        }
    }

    @Override
    public ResultModel<PageModel<Map<String, String>>> getIndexPage(String prescriptionType, String dosageForm, String prepositionContent, String content, String langCode, String uiTypeCode, Integer pageNo, Integer pageSize, String sortType) {
        QueryWrapper<EtcmPxPo> wrapper=new QueryWrapper<>();

        if (StringUtils.isBlank(prescriptionType) && StringUtils.isBlank(dosageForm)){
            return new ResultModel<PageModel<Map<String,String>>>().success(new PageModel<>());
        }

        if (StringUtils.isNotBlank(prescriptionType)){
            String[] typeArr = prescriptionType.split(CommonConsts.SPIT);
            wrapper.in(EtcmPxPo.PX_TYPE_CODE, Arrays.asList(typeArr));
        }

        if (StringUtils.isNotBlank(dosageForm)){
            String[] dosageFormArr = dosageForm.split(CommonConsts.SPIT);
            wrapper.in(EtcmPxPo.PX_DOSAGE_FORM_CODE, Arrays.asList(dosageFormArr));
        }


        if(StringUtils.isNotBlank(prepositionContent)){
            wrapper.and(w->w.like( "px_zh_name", prepositionContent)
                    .or().like( "px_zh_name_py", prepositionContent)
                    .or().like( "px_zh_name_wb", prepositionContent)
                    .or().like( "px_zh_name_abb", prepositionContent)
                    .or().like( "px_en_name", prepositionContent)
                    .or().like( "px_en_name_abb", prepositionContent)
                    .or().like( "px_latin_name", prepositionContent)
                    .or().like( "px_latin_name_abb", prepositionContent)
                    .or().like( "px_name_alias", prepositionContent)
            );
        }
        if(StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like( "px_zh_name", content)
                    .or().like( "px_zh_name_py", content)
                    .or().like( "px_zh_name_wb", content)
                    .or().like( "px_zh_name_abb", content)
                    .or().like( "px_en_name", content)
                    .or().like( "px_en_name_abb", content)
                    .or().like( "px_latin_name", content)
                    .or().like( "px_latin_name_abb", content)
                    .or().like( "px_name_alias", content)
            );
        }
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc(EtcmPxPo.PX_CODE);
        }else {
            wrapper.orderByDesc(EtcmPxPo.PX_CODE);
        }

        wrapper.eq(EtcmPxPo.STATUS, CommonConsts.STR_COMMON_YES);
        IPage<EtcmPxPo> etcmPxPoIPage = this.page(new Page<>(pageNo, pageSize), wrapper);
        List<Map<String,String>> list=new ArrayList<>();
        for(EtcmPxPo etcmPxPo:etcmPxPoIPage.getRecords()){
            List<EtcmPxExPo> exList = etcmPxExService.list(new QueryWrapper<EtcmPxExPo>().eq(EtcmPxExPo.STATUS, CommonConsts.STR_COMMON_YES).eq(EtcmPxExPo.PX_ID, etcmPxPo.getPxCode()).eq(EtcmPxExPo.UI_TYPE_CODE, uiTypeCode).eq(EtcmPxExPo.LANGUAGE_CODE, langCode));
            Map<String,String> map=new HashMap<>(16);
            for(EtcmPxExPo etcmPxExPo:exList){
                map.put(etcmPxExPo.getUiElCode(), etcmPxExPo.getPxExCon());
            }
            list.add(map);
        }
        PageModel<Map<String,String>> page=new PageModel<>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        page.setRecords(list);
        page.setTotalCount(etcmPxPoIPage.getTotal());
        return new ResultModel<PageModel<Map<String,String>>>().success(page);
    }

    @Override
    public ResultModel<EtcmIndexStatusticsRespVO> getStatisticsPx(String prescriptionType, String dosageForm, String prepositionContent, String langCode, String uiTypeCode) {
        QueryWrapper<EtcmPxPo> wrapper=new QueryWrapper<>();
        EtcmIndexStatusticsRespVO vo = new EtcmIndexStatusticsRespVO();
        vo.setPrescriptions(0);
        if (StringUtils.isBlank(prescriptionType) && StringUtils.isBlank(dosageForm)){
            return new ResultModel<EtcmIndexStatusticsRespVO>().success(vo);
        }

        if (StringUtils.isNotBlank(prescriptionType)){
            String[] typeArr = prescriptionType.split(CommonConsts.SPIT);
            wrapper.in(EtcmPxPo.PX_TYPE_CODE, Arrays.asList(typeArr));
        }

        if (StringUtils.isNotBlank(dosageForm)){
            String[] dosageFormArr = dosageForm.split(CommonConsts.SPIT);
            wrapper.in(EtcmPxPo.PX_DOSAGE_FORM_CODE, Arrays.asList(dosageFormArr));
        }


        if(StringUtils.isNotBlank(prepositionContent)){
            wrapper.and(w->w.like( "px_zh_name", prepositionContent)
                    .or().like( "px_zh_name_py", prepositionContent)
                    .or().like( "px_zh_name_wb", prepositionContent)
                    .or().like( "px_zh_name_abb", prepositionContent)
                    .or().like( "px_en_name", prepositionContent)
                    .or().like( "px_en_name_abb", prepositionContent)
                    .or().like( "px_latin_name", prepositionContent)
                    .or().like( "px_latin_name_abb", prepositionContent)
                    .or().like( "px_name_alias", prepositionContent)
            );
        }


        wrapper.eq(EtcmPxPo.STATUS, CommonConsts.STR_COMMON_YES);
        int count = this.count(wrapper);
        vo.setPrescriptions(count);
        return new ResultModel<EtcmIndexStatusticsRespVO>().success(vo);
    }


    @Override
    public List<Map<String, String>> getIndexPageDownload(String prescriptionType, String dosageForm, String prepositionContent, String content, String langCode, String uiTypeCode,String sortType) {

        if (StringUtils.isBlank(prescriptionType) && StringUtils.isBlank(dosageForm)){
            return new ArrayList<>();
        }
        QueryWrapper<EtcmPxPo> queryWrapper = new QueryWrapper<>();

        if (StringUtils.isNotBlank(prescriptionType)){
            String[] typeArr = prescriptionType.split(CommonConsts.SPIT);
            queryWrapper.in("t1.px_type_code", Arrays.asList(typeArr));
        }

        if (StringUtils.isNotBlank(dosageForm)){
            String[] dosageFormArr = dosageForm.split(CommonConsts.SPIT);
            queryWrapper.in("t1.px_dosage_form_code", Arrays.asList(dosageFormArr));
        }


        if(StringUtils.isNotBlank(prepositionContent)){
            queryWrapper.and(w->w.like( "t1.px_zh_name", prepositionContent)
                    .or().like( "t1.px_zh_name_py", prepositionContent)
                    .or().like( "t1.px_zh_name_wb", prepositionContent)
                    .or().like( "t1.px_zh_name_abb", prepositionContent)
                    .or().like( "t1.px_en_name", prepositionContent)
                    .or().like( "t1.px_en_name_abb", prepositionContent)
                    .or().like( "t1.px_latin_name", prepositionContent)
                    .or().like( "t1.px_latin_name_abb", prepositionContent)
                    .or().like( "t1.px_name_alias", prepositionContent)
            );
        }
        if(StringUtils.isNotBlank(content)){
            queryWrapper.and(w->w.like( "t1.px_zh_name", content)
                    .or().like( "t1.px_zh_name_py", content)
                    .or().like( "t1.px_zh_name_wb", content)
                    .or().like( "t1.px_zh_name_abb", content)
                    .or().like( "t1.px_en_name", content)
                    .or().like( "t1.px_en_name_abb", content)
                    .or().like( "t1.px_latin_name", content)
                    .or().like( "t1.px_latin_name_abb", content)
                    .or().like( "t1.px_name_alias", content)
            );
        }


        queryWrapper.eq("t2.language_Code",langCode);
        queryWrapper.eq("t2.ui_type_code",uiTypeCode);
        queryWrapper.eq("t1.status",CommonConsts.COMMON_YES);
        queryWrapper.eq("t2.status",CommonConsts.COMMON_YES);
        if(StringUtils.isNotBlank(sortType) && sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            queryWrapper.orderByAsc("t1.px_code");
        }else {
            queryWrapper.orderByDesc("t1.px_code");
        }
        queryWrapper.groupBy("t1.px_code");
        List<EtcmPxExPo> exList =  etcmPxExMapper.getPxDownload(queryWrapper);


        Map<String,List<EtcmPxExPo>> disMap = new LinkedHashMap<>(16);
        for (EtcmPxExPo record : exList) {
            List<EtcmPxExPo> disList = new ArrayList<>();
            String[] uielcodeList = record.getUiElCode().split("\\|\\|");
            String[] pxExconList = record.getPxExCon().split("\\|\\|");



            for (int i = 0; i < uielcodeList.length; i++) {
                EtcmPxExPo etcmPxExPo = new EtcmPxExPo();
                for (int j = 0; j < pxExconList.length; j++) {
                    etcmPxExPo.setUiElCode(uielcodeList[i]);
                    if (i == j){
                        etcmPxExPo.setPxExCon(pxExconList[j]);
                    }
                }
                disList.add(etcmPxExPo);
            }

            disMap.put(record.getPxCode(), disList);
        }


        List<EtcmUiElPo> etcmUiElPos = etcmPxExMapper.getUIElName(uiTypeCode,langCode);
        List<Map<String, String>> resultList = new ArrayList<>();

        for (String key : disMap.keySet()) {
            Map<String,String> mapRes=new HashMap<>(16);
            List<EtcmPxExPo> values = disMap.get(key);
            List<String> collect = values.stream().map(EtcmPxExPo::getUiElCode).collect(Collectors.toList());
            for (EtcmUiElPo etcmUiElPo : etcmUiElPos) {
                if (collect.contains(etcmUiElPo.getUiElCode())){
                    for (EtcmPxExPo etcmPxExPo : values) {
                        if (etcmUiElPo.getUiElCode().equals(etcmPxExPo.getUiElCode())){
                            mapRes.put(etcmPxExPo.getUiElCode(), etcmPxExPo.getPxExCon());
                        }
                    }
                }else {
                    mapRes.put(etcmUiElPo.getUiElCode(), "");
                }

            }

            resultList.add(mapRes);
        }
        return resultList;
    }



    @Override
    public ResultModel<PageModel<Map<String, String>>> getPage(String prescriptionType, String dosageForm, String content, String langCode,String uiTypeCode, Integer pageNo, Integer pageSize, String sortType) {
        QueryWrapper<EtcmPxPo> wrapper=new QueryWrapper<>();

        if (StringUtils.isBlank(prescriptionType) && StringUtils.isBlank(dosageForm)){
            return new ResultModel<PageModel<Map<String,String>>>().success(new PageModel<>());
        }

        if (StringUtils.isNotBlank(prescriptionType)){
            String[] typeArr = prescriptionType.split(CommonConsts.SPIT);
            wrapper.in(EtcmPxPo.PX_TYPE_CODE, Arrays.asList(typeArr));
        }

        if (StringUtils.isNotBlank(dosageForm)){
            String[] dosageFormArr = dosageForm.split(CommonConsts.SPIT);
            wrapper.in(EtcmPxPo.PX_DOSAGE_FORM_CODE, Arrays.asList(dosageFormArr));
        }


        if(StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like( "px_zh_name", content)
                    .or().like( "px_zh_name_py", content)
                    .or().like( "px_zh_name_wb", content)
                    .or().like( "px_zh_name_abb", content)
                    .or().like( "px_en_name", content)
                    .or().like( "px_en_name_abb", content)
                    .or().like( "px_latin_name", content)
                    .or().like( "px_latin_name_abb", content)
                    .or().like( "px_name_alias", content)
            );
        }
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc(EtcmPxPo.PX_CODE);
        }else {
            wrapper.orderByDesc(EtcmPxPo.PX_CODE);
        }

        wrapper.eq(EtcmPxPo.STATUS, CommonConsts.STR_COMMON_YES);
        IPage<EtcmPxPo> etcmPxPoIPage = this.page(new Page<>(pageNo, pageSize), wrapper);
        List<Map<String,String>> list=new ArrayList<>();
        for(EtcmPxPo etcmPxPo:etcmPxPoIPage.getRecords()){
            List<EtcmPxExPo> exList = etcmPxExService.list(new QueryWrapper<EtcmPxExPo>().eq(EtcmPxExPo.STATUS, CommonConsts.STR_COMMON_YES).eq(EtcmPxExPo.PX_ID, etcmPxPo.getPxCode()).eq(EtcmPxExPo.UI_TYPE_CODE, uiTypeCode).eq(EtcmPxExPo.LANGUAGE_CODE, langCode));
            Map<String,String> map=new HashMap<>(16);
            for(EtcmPxExPo etcmPxExPo:exList){
                map.put(etcmPxExPo.getUiElCode(), etcmPxExPo.getPxExCon());
            }
            list.add(map);
        }
        PageModel<Map<String,String>> page=new PageModel<>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        page.setRecords(list);
        page.setTotalCount(etcmPxPoIPage.getTotal());
        return new ResultModel<PageModel<Map<String,String>>>().success(page);
    }


    @Override
    public ResultModel<EtcmStatisticsRespVo> statisticsPx( String content) {
        QueryWrapper<EtcmPxPo> wrapper=new QueryWrapper<>();
        wrapper.select(EtcmPxPo.PX_DOSAGE_FORM_CODE, EtcmPxPo.PX_TYPE_CODE);
        if(StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like( "px_zh_name", content)
                    .or().like( "px_zh_name_py", content)
                    .or().like( "px_zh_name_wb", content)
                    .or().like( "px_zh_name_abb", content)
                    .or().like( "px_en_name", content)
                    .or().like( "px_en_name_abb", content)
                    .or().like( "px_latin_name", content)
                    .or().like( "px_latin_name_abb", content)
                    .or().like( "px_name_alias", content)
            );
        }

        wrapper.eq(EtcmPxPo.STATUS, CommonConsts.STR_COMMON_YES);
        List<EtcmPxPo> etcmPxPoList = this.list(wrapper);
        EtcmStatisticsRespVo vo = new EtcmStatisticsRespVo();

        Map<String, Long> dmap = etcmPxPoList.stream().map(EtcmPxPo::getPxDosageFormCode).filter(StringUtils::isNotBlank).collect(Collectors.groupingBy(s -> s,Collectors.counting()));
        long count = etcmPxPoList.stream().map(EtcmPxPo::getPxDosageFormCode).filter(StringUtils::isNotBlank).count();
        Map<String, Long> tmap = etcmPxPoList.stream().map(EtcmPxPo::getPxTypeCode).filter(StringUtils::isNotBlank).collect(Collectors.groupingBy(s -> s,Collectors.counting()));
        long count1 = etcmPxPoList.stream().map(EtcmPxPo::getPxTypeCode).filter(StringUtils::isNotBlank).count();
        Map<String, String> dMap = getStatistics(count, dmap);
        Map<String, String> tMap = getStatistics(count1, tmap);

        vo.setDosageFormStatistics(dMap);
        vo.setTypeStatistics(tMap);
        return new ResultModel<EtcmStatisticsRespVo>().success(vo);
    }


    @Override
    public List<Map<String, String>> getPxDownload(String prescriptionType, String dosageForm, String content, String langCode, String uiTypeCode,String sortType) {
        QueryWrapper<EtcmPxPo> wrapper=new QueryWrapper<>();

        if (StringUtils.isBlank(prescriptionType) && StringUtils.isBlank(dosageForm)){
            return new ArrayList<>();
        }

        if (StringUtils.isNotBlank(prescriptionType)){
            String[] typeArr = prescriptionType.split(CommonConsts.SPIT);
            wrapper.in("t1.px_type_code", Arrays.asList(typeArr));
        }

        if (StringUtils.isNotBlank(dosageForm)){
            String[] dosageFormArr = dosageForm.split(CommonConsts.SPIT);
            wrapper.in("t1.px_dosage_form_code", Arrays.asList(dosageFormArr));
        }


        if(StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like( "t1.px_zh_name", content)
                    .or().like( "t1.px_zh_name_py", content)
                    .or().like( "t1.px_zh_name_wb", content)
                    .or().like( "t1.px_zh_name_abb", content)
                    .or().like( "t1.px_en_name", content)
                    .or().like( "t1.px_en_name_abb", content)
                    .or().like( "t1.px_latin_name", content)
                    .or().like( "t1.px_latin_name_abb", content)
                    .or().like( "t1.px_name_alias", content)
            );
        }
        if(StringUtils.isNotBlank(sortType) && sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("t1.px_code");
        }else {
            wrapper.orderByDesc("t1.px_code");
        }

        wrapper.eq("t1.status", CommonConsts.STR_COMMON_YES);
        wrapper.eq("t2.language_code", langCode);
        wrapper.eq("t2.ui_type_code", uiTypeCode);
        wrapper.groupBy("t1.px_code");
       // List<EtcmPxPo> etcmPxPoIPage = this.list(wrapper);


        List<EtcmPxExPo> exList =  etcmPxExMapper.getPxDownload(wrapper);


        Map<String,List<EtcmPxExPo>> disMap = new LinkedHashMap<>(16);
        for (EtcmPxExPo record : exList) {
            List<EtcmPxExPo> disList = new ArrayList<>();
            String[] uielcodeList = record.getUiElCode().split("\\|\\|");
            String[] pxExconList = record.getPxExCon().split("\\|\\|");



            for (int i = 0; i < uielcodeList.length; i++) {
                EtcmPxExPo etcmPxExPo = new EtcmPxExPo();
                for (int j = 0; j < pxExconList.length; j++) {
                    etcmPxExPo.setUiElCode(uielcodeList[i]);
                    if (i == j){
                        etcmPxExPo.setPxExCon(pxExconList[j]);
                    }
                }
                disList.add(etcmPxExPo);
            }

            disMap.put(record.getPxCode(), disList);
        }


        List<EtcmUiElPo> etcmUiElPos = etcmPxExMapper.getUIElName(uiTypeCode,langCode);
        List<Map<String, String>> resultList = new ArrayList<>();

        for (String key : disMap.keySet()) {
            Map<String,String> mapRes=new HashMap<>(16);
            List<EtcmPxExPo> values = disMap.get(key);
            List<String> collect = values.stream().map(EtcmPxExPo::getUiElCode).collect(Collectors.toList());
            for (EtcmUiElPo etcmUiElPo : etcmUiElPos) {
                if (collect.contains(etcmUiElPo.getUiElCode())){
                    for (EtcmPxExPo etcmPxExPo : values) {
                        if (etcmUiElPo.getUiElCode().equals(etcmPxExPo.getUiElCode())){
                            mapRes.put(etcmPxExPo.getUiElCode(), etcmPxExPo.getPxExCon());
                        }
                    }
                }else {
                    mapRes.put(etcmUiElPo.getUiElCode(), "");
                }

            }

            resultList.add(mapRes);
        }
        return resultList;
    }




    @Override
    public ResultModel<List<EtcmCommonBaseInfoRespVO>> getDetails(String prescriptionId, String langCode, String uiTypeCode,String content) {
        List<EtcmPxExPo> exPoIPage = etcmPxExMapper.getPage( new QueryWrapper<EtcmPxExPo>().eq("t1.status", CommonConsts.STR_COMMON_YES).eq("t1.px_id", prescriptionId).eq("t1.ui_type_code", uiTypeCode).eq("t1.language_code", langCode).isNotNull("t1.px_ex_con"));
        List<EtcmCommonBaseInfoRespVO> list=new ArrayList<>();
        for(EtcmPxExPo etcmPxExPo:exPoIPage){
            EtcmCommonBaseInfoRespVO respVO=new EtcmCommonBaseInfoRespVO();
            respVO.setUiElName(etcmPxExPo.getUiElName());
            respVO.setUiElValue(etcmPxExPo.getPxExCon());
            list.add(respVO);
        }
        return new ResultModel<List<EtcmCommonBaseInfoRespVO>>().success(list);
    }

    @Override
    public List<Map<String, String>> getPxDetails(String pxId, String content, String langCode, String uiTypeCode) {
        QueryWrapper<EtcmPxExPo> wrapper=new QueryWrapper<>();
        wrapper.eq("t1.px_id", pxId);
        wrapper.eq("t2.ui_type_code", uiTypeCode);
        wrapper.eq("t2.language_Code", langCode);
        wrapper.isNotNull("t1.px_ex_con");
        wrapper.orderByAsc("t2.ui_el_sort");
        List<EtcmPxExPo> resultList = etcmPxExMapper.getPxDetailsList(wrapper);
        List<Map<String,String>> list=new ArrayList<>();
        Map<String,String> map=new LinkedHashMap<>();
        for(EtcmPxExPo etcmPxExPo:resultList){
            map.put(etcmPxExPo.getUiElName(), etcmPxExPo.getPxExCon());
        }
        list.add(map);
        return list;
    }


    @Override
    public ResultModel<PageModel<Map<String, String>>> getIngredient(String ingrHia, String ingrBbb, String ingrCaco2,String ingrHob,String content, String langCode, String uiTypeCode, String prescriptionId, Integer pageNo, Integer pageSize, String sortType) {
        uiTypeCode = CommonConsts.UI_TYPE_CODE_INGR;
        if (StringUtils.isBlank(ingrHia) && StringUtils.isNotBlank(ingrBbb) && StringUtils.isNotBlank(ingrCaco2) && StringUtils.isNotBlank(ingrHob)){
            return new ResultModel<PageModel<Map<String, String>>>().success(new PageModel<>());
        }

//        List<EtcmPxHerbPo> list = etcmPxHerbService.list(new QueryWrapper<EtcmPxHerbPo>().eq(EtcmPxHerbPo.PX_ID, prescriptionId).eq(EtcmPxHerbPo.STATUS, CommonConsts.COMMON_YES));
//        List<String> herbList=list.stream().map(EtcmPxHerbPo::getHerbId).collect(Collectors.toList());

        QueryWrapper<EtcmHerbIngrPo> wrapper=new QueryWrapper<>();
        if(StringUtils.isNotBlank(ingrHia)){
            String[] msArray = ingrHia.split(CommonConsts.SPIT);
            wrapper.in("t2.ingr_hia_code", Arrays.asList(msArray));
        }
        if(StringUtils.isNotBlank(ingrBbb)){
            String[] tmArray = ingrBbb.split(CommonConsts.SPIT);
            wrapper.in("t2.ingr_bbb_code", Arrays.asList(tmArray));
        }
        if(StringUtils.isNotBlank(ingrCaco2)){
            String[] hlpArray = ingrCaco2.split(CommonConsts.SPIT);
            wrapper.in("t2.ingr_caco2_code", Arrays.asList(hlpArray));
        }
        if(StringUtils.isNotBlank(ingrHob)){
            String[] hlpArray = ingrHob.split(CommonConsts.SPIT);
            wrapper.in("t2.ingr_hob_code", Arrays.asList(hlpArray));
        }
        if(StringUtils.isNotBlank(content)){
            wrapper.and(w -> w.like("t2.ingr_zh_name", content)
                    .or().like("t2.ingr_zh_name_py", content)
                    .or().like("t2.ingr_zh_name_wb", content)
                    .or().like("t2.ingr_zh_name_abb", content)
                    .or().like("t2.ingr_en_name", content)
                    .or().like("t2.ingr_en_name_abb", content)
                    .or().like("t2.ingr_latin_name", content)
                    .or().like("t2.ingr_latin_name_abb", content)
                    .or().like("t2.ingr_name_alias", content)
            );
        }
        wrapper.eq("t1.px_code", prescriptionId);
       // wrapper.in("t1.herb_id", herbList);
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("t1.ingr_id");
        }else {
            wrapper.orderByDesc("t1.ingr_id");
        }
        IPage<EtcmHerbIngrPo> iPage = etcmPxExMapper.getIngr(new Page<>(pageNo, pageSize), wrapper);
        List<Map<String,String>> resultList=new ArrayList<>();
        for(EtcmHerbIngrPo etcmHerbIngrPo:iPage.getRecords()){
            List<EtcmIngrExPo> exList = etcmIngrExService.list(new QueryWrapper<EtcmIngrExPo>().eq(EtcmIngrExPo.INGR_ID, etcmHerbIngrPo.getIngrId()).eq(EtcmIngrExPo.STATUS, CommonConsts.STR_COMMON_YES).eq(EtcmIngrExPo.UI_TYPE_CODE, uiTypeCode).eq(EtcmIngrExPo.LANGUAGE_CODE, langCode));
            Map<String,String> map=new HashMap<>(16);
            if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                map.put(UiElCodeEnums.HERB_NAME.getUiElCode(), etcmHerbIngrPo.getHerbEnName());
            }
            if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                map.put(UiElCodeEnums.HERB_NAME.getUiElCode(), etcmHerbIngrPo.getHerbZhName());
            }
            for(EtcmIngrExPo etcmIngrExPo:exList){
                map.put(etcmIngrExPo.getUiElCode(), etcmIngrExPo.getIngrExCon());
            }
            resultList.add(map);
        }
        PageModel<Map<String,String>> page=new PageModel<>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        page.setRecords(resultList);
        page.setTotalCount(iPage.getTotal());
        return new ResultModel<PageModel<Map<String,String>>>().success(page);
    }

    @Override
    public ResultModel<PxIngrStatisticsRespVo> getIngredientStatistics(String content, String prescriptionId) {
        //List<EtcmPxHerbPo> list = etcmPxHerbService.list(new QueryWrapper<EtcmPxHerbPo>().eq(EtcmPxHerbPo.PX_ID, prescriptionId).eq(EtcmPxHerbPo.STATUS, CommonConsts.COMMON_YES));
        //List<String> herbList=list.stream().map(EtcmPxHerbPo::getHerbId).collect(Collectors.toList());
        QueryWrapper<EtcmIngrPo> wrapper=new QueryWrapper<>();
        if(StringUtils.isNotBlank(content)){
            wrapper.and(w -> w.like("t2.ingr_zh_name", content)
                    .or().like("t2.ingr_zh_name_py", content)
                    .or().like("t2.ingr_zh_name_wb", content)
                    .or().like("t2.ingr_zh_name_abb", content)
                    .or().like("t2.ingr_en_name", content)
                    .or().like("t2.ingr_en_name_abb", content)
                    .or().like("t2.ingr_latin_name", content)
                    .or().like("t2.ingr_latin_name_abb", content)
                    .or().like("t2.ingr_name_alias", content)
            );
        }
        //wrapper.in("t1.herb_id", herbList);
        wrapper.eq("t1.px_code", prescriptionId);
        List<EtcmIngrPo> ingrList = etcmPxExMapper.getIngrList(wrapper);
        Map<String, Long> ingrBbbMap = ingrList.stream().filter(etcmIngrPo -> StringUtils.isNotBlank(etcmIngrPo.getIngrBbbCode())).collect(Collectors.groupingBy(EtcmIngrPo::getIngrBbbCode, Collectors.counting()));
        long ingrBbbCount = ingrList.stream().filter(etcmIngrPo -> StringUtils.isNotBlank(etcmIngrPo.getIngrBbbCode())).count();
        Map<String, Long> ingrCaco2Map = ingrList.stream().filter(etcmIngrPo -> StringUtils.isNotBlank(etcmIngrPo.getIngrCaco2Code())).collect(Collectors.groupingBy(EtcmIngrPo::getIngrCaco2Code, Collectors.counting()));
        long ingrCaco2Count = ingrList.stream().filter(etcmIngrPo -> StringUtils.isNotBlank(etcmIngrPo.getIngrCaco2Code())).count();
        Map<String, Long> ingrHiaMap = ingrList.stream().filter(etcmIngrPo -> StringUtils.isNotBlank(etcmIngrPo.getIngrHiaCode())).collect(Collectors.groupingBy(EtcmIngrPo::getIngrHiaCode, Collectors.counting()));
        long ingrHiaCount = ingrList.stream().filter(etcmIngrPo -> StringUtils.isNotBlank(etcmIngrPo.getIngrHiaCode())).count();
        Map<String, Long> ingrHobMap = ingrList.stream().filter(etcmIngrPo -> StringUtils.isNotBlank(etcmIngrPo.getIngrHobCode())).collect(Collectors.groupingBy(EtcmIngrPo::getIngrHobCode, Collectors.counting()));
        long ingrHobCount = ingrList.stream().filter(etcmIngrPo -> StringUtils.isNotBlank(etcmIngrPo.getIngrHobCode())).count();
        List<String> ingrBbbList = getIngrStatistics(ingrBbbCount, ingrBbbMap);
        List<String> ingrCaco2List = getIngrStatistics(ingrCaco2Count, ingrCaco2Map);
        List<String> ingrHiaList = getIngrStatistics(ingrHiaCount, ingrHiaMap);
        List<String> ingrHobList = getIngrStatistics(ingrHobCount, ingrHobMap);
        PxIngrStatisticsRespVo vo = new PxIngrStatisticsRespVo();
        vo.setIngrBbb(ingrBbbList);
        vo.setIngrCaco2(ingrCaco2List);
        vo.setIngrHia(ingrHiaList);
        vo.setIngrHob(ingrHobList);
        return new ResultModel<PxIngrStatisticsRespVo>().success(vo);
    }
    @Override
    public List<Map<String, String>> getIngredientDownload(String ingrHia, String ingrBbb, String ingrCaco2, String ingrHob, String content, String langCode, String uiTypeCode, String prescriptionId, String sortType) {
        uiTypeCode = CommonConsts.UI_TYPE_CODE_INGR;
        if (StringUtils.isBlank(ingrHia) && StringUtils.isNotBlank(ingrBbb) && StringUtils.isNotBlank(ingrCaco2) && StringUtils.isNotBlank(ingrHob)){
            return new ArrayList<>();
        }

        QueryWrapper<EtcmHerbIngrPo> wrapper=new QueryWrapper<>();
        if(StringUtils.isNotBlank(ingrHia)){
            String[] msArray = ingrHia.split(CommonConsts.SPIT);
            wrapper.in("t2.ingr_hia_code", Arrays.asList(msArray));
        }
        if(StringUtils.isNotBlank(ingrBbb)){
            String[] tmArray = ingrBbb.split(CommonConsts.SPIT);
            wrapper.in("t2.ingr_bbb_code", Arrays.asList(tmArray));
        }
        if(StringUtils.isNotBlank(ingrCaco2)){
            String[] hlpArray = ingrCaco2.split(CommonConsts.SPIT);
            wrapper.in("t2.ingr_caco2_code", Arrays.asList(hlpArray));
        }
        if(StringUtils.isNotBlank(ingrHob)){
            String[] hlpArray = ingrHob.split(CommonConsts.SPIT);
            wrapper.in("t2.ingr_hob_code", Arrays.asList(hlpArray));
        }
        if(StringUtils.isNotBlank(content)){
            wrapper.and(w -> w.like("t2.ingr_zh_name", content)
                    .or().like("t2.ingr_zh_name_py", content)
                    .or().like("t2.ingr_zh_name_wb", content)
                    .or().like("t2.ingr_zh_name_abb", content)
                    .or().like("t2.ingr_en_name", content)
                    .or().like("t2.ingr_en_name_abb", content)
                    .or().like("t2.ingr_latin_name", content)
                    .or().like("t2.ingr_latin_name_abb", content)
                    .or().like("t2.ingr_name_alias", content)
            );
        }
        wrapper.eq("t1.px_code", prescriptionId);
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("t4.ingr_id");
        }else {
            wrapper.orderByDesc("t4.ingr_id");
        }
        wrapper.groupBy("t1.herb_id,t4.ingr_id,t4.ui_el_code,t4.ingr_ex_con,t3.herb_en_name,t3.herb_zh_name");
        List<EtcmIngrExPo> iPage = etcmPxExMapper.getIngredientDownload(wrapper,uiTypeCode,langCode);


        Map<String,List<EtcmIngrExPo>> disMap = new LinkedHashMap<>(16);
        for (EtcmIngrExPo record : iPage) {
            List<EtcmIngrExPo> disList = new ArrayList<>();

            String[] uiElCodeList = record.getUiElCode().split("\\|\\|");
            String[] herbExConList = record.getIngrExCon().split("\\|\\|");
            for (int i = 0; i < uiElCodeList.length; i++) {
                EtcmIngrExPo etcmHerbExPo = new EtcmIngrExPo();

                for (int j = 0; j < herbExConList.length; j++) {
                    if (i == j){
                        etcmHerbExPo.setUiElCode(uiElCodeList[i]);
                        etcmHerbExPo.setIngrExCon(herbExConList[j]);
                        etcmHerbExPo.setHerbEnName(record.getHerbEnName());
                        etcmHerbExPo.setHerbZhName(record.getHerbZhName());

                    }
                }
                disList.add(etcmHerbExPo);
            }

            disMap.put(record.getIngrId()+record.getHerbId(),disList);
        }


        List<EtcmUiElPo> etcmUiElPos = etcmPxExMapper.getUIElName(uiTypeCode,langCode);
        etcmUiElPos = etcmUiElPos.stream().filter(s -> s.getUiElSort() < 3 || (s.getUiElSort() > 6  && s.getUiElSort() < 12)).sorted(Comparator.comparing(EtcmUiElPo::getUiElSort)).collect(Collectors.toList());

        List<Map<String, String>> resultList = new ArrayList<>();

        for (String key : disMap.keySet()) {
            Map<String,String> mapRes=new HashMap<>(16);
            List<EtcmIngrExPo> values = disMap.get(key);
            List<String> collect = values.stream().map(EtcmIngrExPo::getUiElCode).collect(Collectors.toList());
            for (EtcmUiElPo etcmUiElPo : etcmUiElPos) {

                if (collect.contains(etcmUiElPo.getUiElCode())){
                    for (EtcmIngrExPo etcmHerbExPo : values) {
                        if (etcmUiElPo.getUiElCode().equals(etcmHerbExPo.getUiElCode())){
                            mapRes.put(etcmHerbExPo.getUiElCode(), etcmHerbExPo.getIngrExCon());
                            if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                                mapRes.put(UiElCodeEnums.HERB_NAME.getUiElCode(), etcmHerbExPo.getHerbEnName());
                            }
                            if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                                mapRes.put(UiElCodeEnums.HERB_NAME.getUiElCode(), etcmHerbExPo.getHerbZhName());
                            }
                        }
                    }
                }else {
                    mapRes.put(etcmUiElPo.getUiElCode(), "");
                }

            }

            resultList.add(mapRes);
        }

        return resultList;
    }

    @Override
    public ResultModel<PageModel<Map<String, String>>> getTarget(String targetType,String content, String langCode, String uiTypeCode, String prescriptionId, Integer pageNo, Integer pageSize, String sortType) {
        if (StringUtils.isBlank(targetType)){
            return new ResultModel<PageModel<Map<String, String>>>().success(new PageModel<>());
        }
        QueryWrapper<EtcmTargetPo> wrapper=new QueryWrapper<>();
        wrapper.eq("t1.px_code", prescriptionId);
        wrapper.eq("t6.language_code", langCode);
        if(StringUtils.isNotBlank(targetType)){
            String[] targetArray = targetType.split(CommonConsts.SPIT);
            wrapper.in("t3.target_type_code", targetArray);
        }
        if(StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like("t3.target_zh_name", content)
                    .or().like("t3.target_zh_name_py", content)
                    .or().like("t3.target_zh_name_wb", content)
                    .or().like("t3.target_zh_name_abb", content)
                    .or().like("t3.target_en_name", content)
                    .or().like("t3.target_en_name_abb", content)
                    .or().like("t3.target_latin_name", content)
                    .or().like("t3.target_latin_name_abb", content)
                    .or().like("t3.target_name_alias", content));
        }
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("t2.target_id");
        }else {
            wrapper.orderByDesc("t2.target_id");
        }
        IPage<EtcmIngrTargetPo> pageTarget = etcmPxExMapper.getTarget(new Page(pageNo, pageSize), wrapper);
        List<Map<String,String>> resultList=new ArrayList<>();

        List<EtcmUiElPo> uiElName = etcmPxExMapper.getUIElName(uiTypeCode, langCode);
        pageTarget.getRecords().forEach(etcmIngrTargetPo -> {
            Map<String, String> map = getStringStringMap(langCode, etcmIngrTargetPo, uiElName);
            resultList.add(map);
        });
        PageModel<Map<String,String>> page=new PageModel<>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        page.setRecords(resultList);
        page.setTotalCount(pageTarget.getTotal());
        return new ResultModel<PageModel<Map<String,String>>>().success(page);
    }
    @Override
    public List<Map<String, String>> getTargetDownload(String type, String content, String langCode, String uiTypeCode, String prescriptionId, String sortType) {
        if (StringUtils.isBlank(type)){
            return new ArrayList<>();
        }
        QueryWrapper<EtcmTargetExPo> wrapper=new QueryWrapper<>();
        wrapper.eq("t1.px_code", prescriptionId);
        wrapper.eq("t6.language_code", langCode);
        if(StringUtils.isNotBlank(type)){
            String[] targetArray = type.split(CommonConsts.SPIT);
            wrapper.in("t3.target_type_code", targetArray);
        }
        if(StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like("t3.target_zh_name", content)
                    .or().like("t3.target_zh_name_py", content)
                    .or().like("t3.target_zh_name_wb", content)
                    .or().like("t3.target_zh_name_abb", content)
                    .or().like("t3.target_en_name", content)
                    .or().like("t3.target_en_name_abb", content)
                    .or().like("t3.target_latin_name", content)
                    .or().like("t3.target_latin_name_abb", content)
                    .or().like("t3.target_name_alias", content));
        }
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("t2.target_id");
        }else {
            wrapper.orderByDesc("t2.target_id");
        }
        List<EtcmIngrTargetPo> pageTarget = etcmPxExMapper.getTargetDownload( wrapper);
        List<Map<String,String>> resultList=new ArrayList<>();

        List<EtcmUiElPo> uiElName = etcmPxExMapper.getUIElName(uiTypeCode, langCode);
        pageTarget.forEach(etcmIngrTargetPo -> {
            Map<String, String> map = getStringStringMapDownload(langCode, etcmIngrTargetPo, uiElName);
            resultList.add(map);
        });
        return resultList;
    }
    @Override
    public ResultModel<Map<String, String>> getTargetStatistics( String content, String prescriptionId) {
        QueryWrapper<EtcmTargetPo> wrapper=new QueryWrapper<>();
        wrapper.eq("t1.px_code", prescriptionId);
        if(StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like("t3.target_zh_name", content)
                    .or().like("t3.target_zh_name_py", content)
                    .or().like("t3.target_zh_name_wb", content)
                    .or().like("t3.target_zh_name_abb", content)
                    .or().like("t3.target_en_name", content)
                    .or().like("t3.target_en_name_abb", content)
                    .or().like("t3.target_latin_name", content)
                    .or().like("t3.target_latin_name_abb", content)
                    .or().like("t3.target_name_alias", content));
        }

        List<EtcmTargetPo> list = etcmPxExMapper.getTargetList( wrapper);
        Map<String, Long> map = list.stream().map(EtcmTargetPo::getTargetTypeCode).filter(Objects::nonNull).collect(Collectors.groupingBy(s -> s,Collectors.counting()));
        long count = list.stream().map(EtcmTargetPo::getTargetTypeCode).filter(Objects::nonNull).count();
        Map<String, String> res = getStatistics(count, map);
        return new ResultModel<Map<String, String>>().success(res);
    }


    @Override
    public ResultModel<PageModel<Map<String, String>>> getExperimental(String content, String prescriptionId, String langCode, String uiTypeCode, Integer pageNo, Integer pageSize, String sortType) {

        QueryWrapper<EtcmExperimentalRecordsPo> wrapper=new QueryWrapper<>();
        wrapper.eq("t1.px_code", prescriptionId);
        if(StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like("t3.er_zh_name", content)
                    .or().like("t3.er_zh_name_py", content)
                    .or().like("t3.er_zh_name_wb", content)
                    .or().like("t3.er_zh_name_abb", content)
                    .or().like("t3.er_en_name", content)
                    .or().like("t3.er_en_name_abb", content)
                    .or().like("t3.er_latin_name", content)
                    .or().like("t3.er_latin_name_abb", content)
                    .or().like("t3.er_name_alias", content));
        }
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("t2.er_id");
        }else {
            wrapper.orderByDesc("t2.er_id");
        }
        IPage<EtcmExperimentalRecordsIngrPo> pageEr = etcmPxExMapper.getExperimental(new Page(pageNo, pageSize), wrapper);
        List<Map<String,String>> resultList=new ArrayList<>();

        List<EtcmUiElPo> uiElName = etcmPxExMapper.getUIElName(uiTypeCode, langCode);
        for (EtcmExperimentalRecordsIngrPo record : pageEr.getRecords()) {
            Map<String, String> map = getStringStringMap(langCode, record, uiElName);
            resultList.add(map);
        }

        PageModel<Map<String,String>> page=new PageModel<>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        page.setRecords(resultList);
        page.setTotalCount(pageEr.getTotal());
        return new ResultModel<PageModel<Map<String,String>>>().success(page);
    }
    @Override
    public List<Map<String, String>> getExperimentalList(String content, String prescriptionId, String langCode, String uiTypeCode,String sortType) {
        QueryWrapper<EtcmExperimentalRecordsPo> wrapper=new QueryWrapper<>();
        wrapper.eq("t1.px_code", prescriptionId);
        if(StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like("t3.er_zh_name", content)
                    .or().like("t3.er_zh_name_py", content)
                    .or().like("t3.er_zh_name_wb", content)
                    .or().like("t3.er_zh_name_abb", content)
                    .or().like("t3.er_en_name", content)
                    .or().like("t3.er_en_name_abb", content)
                    .or().like("t3.er_latin_name", content)
                    .or().like("t3.er_latin_name_abb", content)
                    .or().like("t3.er_name_alias", content));
        }
        if(StringUtils.isNotBlank(sortType) && sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("t2.er_id");
        }else {
            wrapper.orderByDesc("t2.er_id");
        }
        List<EtcmExperimentalRecordsIngrPo> pageEr = etcmPxExMapper.getExperimentalList(wrapper);
        List<Map<String,String>> resultList=new ArrayList<>();

        List<EtcmUiElPo> uiElName = etcmPxExMapper.getUIElName(uiTypeCode, langCode);
        pageEr.forEach(recordsIngrPo -> {
            Map<String, String> map = getStringStringMapDownload(langCode, recordsIngrPo, uiElName);
            resultList.add(map);
        });
        return resultList;
    }




    @Override
    public ResultModel<NetworkStatisticsRespVo> networkStatistics(String prescriptionId, String langCode, String uiTypeCode) {
        List<EtcmHerbHerbPo> herbAndHerbList = etcmPxExMapper.getHerbAndHerbByPxId(prescriptionId, langCode);
        List<String> mylist=new ArrayList<>();
        List<EtcmHerbHerbPo> herbAndHerbList_new= new ArrayList<>();
        for(EtcmHerbHerbPo it:herbAndHerbList){
            if (!mylist.contains(it.getHerbCode()+it.getTargetHerbCode()) && !mylist.contains(it.getTargetHerbCode()+it.getHerbCode()) && !it.getHerbCode().equals(it.getTargetHerbCode())) {
                mylist.add(it.getHerbCode()+it.getTargetHerbCode());
                herbAndHerbList_new.add(it);
            }
        }

        List<HerbIngrVo> herbAndIngrList = etcmPxExMapper.getHerbAndIngrByPxId(prescriptionId, langCode);

        List<String> ingrList=new ArrayList<>();
        for (HerbIngrVo it:herbAndIngrList){
            if(!ingrList.contains(it.getIngrId())){
                ingrList.add(it.getIngrId());
            }
        }
        int count = ingrList.isEmpty() ? 0:ingrList.size()*(ingrList.size()-1)/2;
        QueryWrapper<EtcmIngrIngrPo> ingrAndIngrWrapper = new QueryWrapper<>();
        ingrAndIngrWrapper.in("C.ingr_code",ingrList).in("C.target_ingr_code",ingrList).last("limit "+String.valueOf(count));
        List<EtcmIngrIngrPo> ingrAndIngrList = etcmPxExMapper.getIngrAndIngrByPxId(ingrAndIngrWrapper);
        List<String> mylist_2=new ArrayList<>();
        List<EtcmIngrIngrPo> ingrAndIngrList_new= new ArrayList<>();
        for(EtcmIngrIngrPo it:ingrAndIngrList){
            if (!mylist_2.contains(it.getIngrCode()+it.getTargetIngrCode()) && !mylist_2.contains(it.getTargetIngrCode()+it.getIngrCode()) && !it.getIngrCode().equals(it.getTargetIngrCode())) {
                mylist_2.add(it.getIngrCode()+it.getTargetIngrCode());
                ingrAndIngrList_new.add(it);
            }
        }



        PxNetworkStatisticsRespVo res = getPxNetworkStatisticsRespVoResultModel(langCode, null, null, null, null, herbAndHerbList_new, ingrAndIngrList_new, herbAndIngrList);
        NetworkStatisticsRespVo vo = new NetworkStatisticsRespVo();
        vo.setScatterDiagram(res.getScatterDiagram());
        return new ResultModel<NetworkStatisticsRespVo>().success(vo);
    }



    @Override
    public ResultModel<PageModel<Map<String, String>>> networkPage(String prescriptionId, String langCode, String uiTypeCode, Integer pageNo, Integer pageSize) {
        List<EtcmHerbHerbPo> herbAndHerbList = etcmPxExMapper.getHerbAndHerbByPxId(prescriptionId, langCode);
        List<String> mylist=new ArrayList<>();
        List<EtcmHerbHerbPo> herbAndHerbList_new= new ArrayList<>();
        for(EtcmHerbHerbPo it:herbAndHerbList){
            if (!mylist.contains(it.getHerbCode()+it.getTargetHerbCode()) && !mylist.contains(it.getTargetHerbCode()+it.getHerbCode()) && !it.getHerbCode().equals(it.getTargetHerbCode())) {
                mylist.add(it.getHerbCode()+it.getTargetHerbCode());
                herbAndHerbList_new.add(it);
            }
        }

        List<HerbIngrVo> herbAndIngrList = etcmPxExMapper.getHerbAndIngrByPxId(prescriptionId, langCode);
        //List<EtcmUiElPo> uiElNameList = etcmPxExMapper.getUIElName(uiTypeCode, langCode);

        List<String> ingrList=new ArrayList<>();
        for (HerbIngrVo it:herbAndIngrList){
            if(!ingrList.contains(it.getIngrId())){
                ingrList.add(it.getIngrId());
            }
        }
        int count = ingrList.isEmpty() ? 0:ingrList.size()*(ingrList.size()-1)/2;
        QueryWrapper<EtcmIngrIngrPo> ingrAndIngrWrapper = new QueryWrapper<>();
        ingrAndIngrWrapper.in("C.ingr_code",ingrList).in("C.target_ingr_code",ingrList).last("limit "+String.valueOf(count));
        List<EtcmIngrIngrPo> ingrAndIngrList = etcmPxExMapper.getIngrAndIngrByPxId(ingrAndIngrWrapper);
        List<String> mylist_2=new ArrayList<>();
        List<EtcmIngrIngrPo> ingrAndIngrList_new= new ArrayList<>();
        for(EtcmIngrIngrPo it:ingrAndIngrList){
            if (!mylist_2.contains(it.getIngrCode()+it.getTargetIngrCode()) && !mylist_2.contains(it.getTargetIngrCode()+it.getIngrCode()) && !it.getIngrCode().equals(it.getTargetIngrCode())) {
                mylist_2.add(it.getIngrCode()+it.getTargetIngrCode());
                ingrAndIngrList_new.add(it);
            }
        }

        List<EtcmUiElPo> uiElNameList = etcmPxExMapper.getUIElName(uiTypeCode, langCode);

        PageModel<Map<String, String>> page = getNetworkTablePage(langCode, null, null, null, null, herbAndHerbList_new, ingrAndIngrList_new, herbAndIngrList, uiElNameList, pageNo, pageSize);
        return new ResultModel<PageModel<Map<String, String>>>().success(page);
    }


    @Override
    public ResultModel<NetworkStatisticsRespVo> getHerbHerb(HerbHerbReqVo reqVo) {
        HerbHerbPageReqVo pageReqVo = new HerbHerbPageReqVo();
        BeanUtils.copyProperties(reqVo, pageReqVo);
//        ResultModel<PxNetworkStatisticsRespVo> data = getNetwork(pageReqVo, false, false, false, false, true, true, true, 1);
        ResultModel<PxNetworkStatisticsRespVo> data = getNetwork(pageReqVo, false, false, false, false, true, true, true, 1);
        if (!data.isSuccess()){
            return new ResultModel<NetworkStatisticsRespVo>().failure(data.getMessage());
        }

        NetworkStatisticsRespVo vo = new NetworkStatisticsRespVo();
        vo.setScatterDiagram(data.getData().getScatterDiagram());
        return new ResultModel<NetworkStatisticsRespVo>().success(vo);
    }




    @Override
    public ResultModel<PxNetworkStatisticsRespVo> getNetwork(HerbHerbPageReqVo reqVo,boolean isPxDisease,boolean isHerbDisease,boolean isIngrDisease,boolean isPxHerb,boolean isHerbHerb,boolean isIngrIngr,boolean isHerbIngr,int numberType){
//        if (reqVo.getSourceName().isEmpty() && reqVo.getTargetName().isEmpty()){
//            return new ResultModel<PxNetworkStatisticsRespVo>().success();
//        }

        List<EtcmPxHerbPo> pxAndHerbList = new ArrayList<>();
        List<EtcmPxHerbPo> pxAndHerbListRes = new ArrayList<>();
        List<EtcmPxHerbPo> pxAndHerbListNew = new ArrayList<>();

        if (isPxHerb){
            QueryWrapper<EtcmPxHerbPo> pxherbWrapper = new QueryWrapper<>();
//            herbAndDiseaseWrapper.isNotNull("t1.id");
            //herbAndDiseaseWrapper.orderByDesc("t1.herb_disease_distance");
//            herbAndDiseaseWrapper.last("limit 50");
            List<String> px_list = new ArrayList<>();
            for (String key : reqVo.getTargetName())
                px_list.add(key);
            pxherbWrapper.in("C.px_id",px_list);
            pxAndHerbList = etcmPxExMapper.getPxAndHerbByHerbID(pxherbWrapper);

        }

        List<PxDiseaseRespVo> pxAndDiseaseListNew = new ArrayList<>();
        List<PxDiseaseRespVo> pxAndDiseaseListRes = new ArrayList<>();
        List<PxDiseaseRespVo> pxAndDiseaseList = new ArrayList<>();
        if (isPxDisease){
            QueryWrapper<PxDiseaseRespVo> herbAndDiseaseWrapper = new QueryWrapper<>();
            herbAndDiseaseWrapper.isNotNull("t1.id");
            //herbAndDiseaseWrapper.orderByDesc("t1.herb_disease_distance");
            herbAndDiseaseWrapper.isNotNull("t1.herb_disease_distance");
            herbAndDiseaseWrapper.gt("t1.herb_disease_distance",0);
            herbAndDiseaseWrapper.last("limit 50");
            pxAndDiseaseList = etcmPxExMapper.getPxAndDiseaseByHerbName(herbAndDiseaseWrapper);


            pxAndDiseaseListNew = new ArrayList<>();
            if (StringUtils.isNotBlank(reqVo.getSourceName())){
                for (PxDiseaseRespVo pxDiseaseRespVo : pxAndDiseaseList) {
                    if (reqVo.getSourceName().equals(pxDiseaseRespVo.getDiseaseId())){
                        pxAndDiseaseListNew.add(pxDiseaseRespVo);
                    }
                }

//                if (CommonConsts.LANG_CODE_ENG.equals(reqVo.getLangCode())){
//                    for (String key : reqVo.getSourceName()) {
//                        List<PxDiseaseRespVo> collect = pxAndDiseaseList.stream().filter(s -> StringUtils.isNotBlank(s.getPxEnName()) && s.getPxEnName().equals(key)).collect(Collectors.toList());
//                        pxAndDiseaseListNew.addAll(collect);
//                    }
//
//                }else if (CommonConsts.LANG_CODE_CHN.equals(reqVo.getLangCode())){
//                    for (String key : reqVo.getSourceName().keySet()) {
//                        if (CommonConsts.STR_COMMON_YES.equals(reqVo.getSourceName().get(key))){
//                            List<PxDiseaseRespVo> collect = pxAndDiseaseList.stream().filter(s -> StringUtils.isNotBlank(s.getPxZhName()) && s.getPxZhName().equals(key)).collect(Collectors.toList());
//                            pxAndDiseaseListNew.addAll(collect);
//                        }else {
//                            List<PxDiseaseRespVo> collect = pxAndDiseaseList.stream().filter(s -> StringUtils.isNotBlank(s.getPxZhName()) && s.getPxZhName().contains(key)).collect(Collectors.toList());
//                            pxAndDiseaseListNew.addAll(collect);
//                        }
//                    }
//
//                }
            }

            pxAndDiseaseListRes = new ArrayList<>();
            if (!CollectionUtils.isEmpty(reqVo.getTargetName())){
                pxAndDiseaseListRes = pxAndDiseaseListNew.stream().filter(item -> reqVo.getTargetName().contains(item)).collect(Collectors.toList());

//                if (CommonConsts.LANG_CODE_ENG.equals(reqVo.getLangCode())){
//                    for (String key : reqVo.getTargetName().keySet()) {
//                        if (CommonConsts.STR_COMMON_YES.equals(reqVo.getTargetName().get(key))){
//                            List<PxDiseaseRespVo> collect = pxAndDiseaseListNew.stream().filter(s -> StringUtils.isNotBlank(s.getDiseaseEnName()) && s.getDiseaseEnName().equals(key)).collect(Collectors.toList());
//                            pxAndDiseaseListRes.addAll(collect);
//                        }else if (CommonConsts.SEARCH_TYPE_2.equals(reqVo.getTargetName().get(key))){
//                            List<PxDiseaseRespVo> collect = pxAndDiseaseListNew.stream().filter(s -> StringUtils.isNotBlank(s.getDiseaseEnName()) && StringUtils.containsIgnoreCase(s.getDiseaseEnName(),key)).collect(Collectors.toList());
//                            pxAndDiseaseListRes.addAll(collect);
//                        }
//                    }
//
//                }else if (CommonConsts.LANG_CODE_CHN.equals(reqVo.getLangCode())){
//                    for (String key : reqVo.getTargetName().keySet()) {
//                        if (CommonConsts.STR_COMMON_YES.equals(reqVo.getTargetName().get(key))){
//                            List<PxDiseaseRespVo> collect = pxAndDiseaseListNew.stream().filter(s -> StringUtils.isNotBlank(s.getDiseaseZhName()) && s.getDiseaseZhName().equals(key)).collect(Collectors.toList());
//                            pxAndDiseaseListRes.addAll(collect);
//                        }else if (CommonConsts.SEARCH_TYPE_2.equals(reqVo.getTargetName().get(key))){
//                            List<PxDiseaseRespVo> collect = pxAndDiseaseListNew.stream().filter(s -> StringUtils.isNotBlank(s.getDiseaseZhName()) && s.getDiseaseZhName().contains(key)).collect(Collectors.toList());
//                            pxAndDiseaseListRes.addAll(collect);
//                        }
//                    }
//
//                }
            }
        }



        List<EtcmHerbHerbPo> herbAndHerbList = new ArrayList<>();
        if (isHerbHerb){
            if(isPxHerb){
                //获取herb列表
                List<String> herbidlist = new ArrayList<>();
                for(EtcmPxHerbPo it:pxAndHerbList){
                    if(!herbidlist.contains(it.getHerbId()))
                        herbidlist.add(it.getHerbId());
                }
                //查询herb-herb
                QueryWrapper<EtcmHerbHerbPo> herbWrapper = new QueryWrapper<>();
                herbWrapper.in(!CollectionUtils.isEmpty(herbidlist),"C.herb_code",herbidlist);
                herbWrapper.in(!CollectionUtils.isEmpty(herbidlist),"C.target_herb_code",herbidlist);
//                herbWrapper.isNotNull("C.herb_herb_distance");
//                herbWrapper.gt("C.herb_herb_distance",0);
                int count = herbidlist.size();
                herbWrapper.last("limit "+String.valueOf(count*(count-1)/2));
                herbAndHerbList = etcmPxExMapper.getHerbAndHerbByHerbID(herbWrapper);
            }
            else {
                if(isHerbDisease){
                    QueryWrapper<EtcmHerbHerbPo> herbWrapper = new QueryWrapper<>();
                    List<String> herb_list = new ArrayList<>();
                    for (String key : reqVo.getTargetName())
                        herb_list.add(key);
                    herbWrapper.in(!CollectionUtils.isEmpty(herb_list),"C.herb_code",herb_list);
                    herbWrapper.in(!CollectionUtils.isEmpty(herb_list),"C.target_herb_code",herb_list);
                    herbWrapper.isNotNull("C.herb_herb_distance");
                    herbWrapper.gt("C.herb_herb_distance",0);
                    int count = herb_list.size();
                    herbWrapper.last("limit "+String.valueOf(count*(count-1)/2));
                    herbAndHerbList = etcmPxExMapper.getHerbAndHerbByHerbID(herbWrapper);
                }
                else {
                    QueryWrapper<EtcmHerbHerbPo> herbWrapper = new QueryWrapper<>();
                    List<String> herb_list = new ArrayList<>();
//                    for (String key : reqVo.getSourceName())
//                        herb_list.add(key);
                    for (String key : reqVo.getTargetName())
                        herb_list.add(key);
                    herb_list.add(reqVo.getSourceName());
                    herbWrapper.in(!CollectionUtils.isEmpty(herb_list),"C.herb_code",herb_list);
                    herbWrapper.in(!CollectionUtils.isEmpty(herb_list),"C.target_herb_code",herb_list);
                    herbWrapper.isNotNull("C.herb_herb_distance");
                    herbWrapper.gt("C.herb_herb_distance",0);
                    herbAndHerbList = etcmPxExMapper.getHerbAndHerbByHerbID(herbWrapper);
                    System.out.println("################herbherb############");
                }
            }
        }


        List<HerbIngrVo> herbAndIngrList = new ArrayList<>();
        if (isHerbIngr){
            if(isPxHerb){
                //获取herb列表
                List<String> herbidlist = new ArrayList<>();
                for(EtcmPxHerbPo it:pxAndHerbList){
                    if(!herbidlist.contains(it.getHerbId()))
                        herbidlist.add(it.getHerbId());
                }
                //查询herb-ingr
                QueryWrapper<HerbIngrVo> herbIngrWrapper = new QueryWrapper<>();
                herbIngrWrapper.in(!CollectionUtils.isEmpty(herbidlist),"C.herb_id",herbidlist);
//                herbIngrWrapper.isNotNull("C.herb_ingr_distance");
//                herbIngrWrapper.gt("C.herb_ingr_distance",0);
                herbAndIngrList = etcmPxExMapper.getHerbAndIngrByHerbID(herbIngrWrapper);
            }
            else{
                if(isHerbDisease){
                    QueryWrapper<HerbIngrVo> herbIngrWrapper = new QueryWrapper<>();
                    List<String> herb_list = new ArrayList<>();
                    for (String key : reqVo.getTargetName())
                        herb_list.add(key);
                    herbIngrWrapper.in(!CollectionUtils.isEmpty(herb_list),"C.herb_id",herb_list);
//                    herbIngrWrapper.isNotNull("C.herb_ingr_distance");
//                    herbIngrWrapper.gt("C.herb_ingr_distance",0);
                    herbAndIngrList = etcmPxExMapper.getHerbAndIngrByHerbID(herbIngrWrapper);
                }
                else {
                    QueryWrapper<HerbIngrVo> herbIngrWrapper = new QueryWrapper<>();
                    List<String> herb_list = new ArrayList<>();
//                    for (String key : reqVo.getSourceName())
//                        herb_list.add(key);
                    for (String key : reqVo.getTargetName())
                        herb_list.add(key);
                    herb_list.add(reqVo.getSourceName());
                    herbIngrWrapper.in(!CollectionUtils.isEmpty(herb_list),"C.herb_id",herb_list);
//                    herbIngrWrapper.isNotNull("C.herb_ingr_distance");
//                    herbIngrWrapper.gt("C.herb_ingr_distance",0);
                    herbAndIngrList = etcmPxExMapper.getHerbAndIngrByHerbID(herbIngrWrapper);
                    System.out.println("################herbingr############");
                }
            }
        }




        List<EtcmIngrIngrPo> ingrAndIngrList = new ArrayList<>();
        if (isIngrIngr){
            //px-dis   herb-dis
            if (isPxHerb || isHerbDisease){
                //获取ingr列表
                List<String> ingridlist = new ArrayList<>();
                for(HerbIngrVo it:herbAndIngrList){
                    if(!ingridlist.contains(it.getIngrId()))
                        ingridlist.add(it.getIngrId());
                }
                //查询ingr-ingr
                QueryWrapper<EtcmIngrIngrPo> ingrWrapper = new QueryWrapper<>();
                ingrWrapper.in(!CollectionUtils.isEmpty(ingridlist),"C.ingr_code",ingridlist)
                        .in(!CollectionUtils.isEmpty(ingridlist),"C.target_ingr_code",ingridlist)
                        .isNotNull("C.ingr_ingr_distance")
                        .gt("C.ingr_ingr_distance",0)
                        .last("limit 100");
                ingrAndIngrList = etcmPxExMapper.getIngrAndIngrByIngrID(ingrWrapper);
                List<String> mylist_2=new ArrayList<>();
                List<EtcmIngrIngrPo> ingrAndIngrList_new= new ArrayList<>();
                for(EtcmIngrIngrPo it:ingrAndIngrList){
                    if (!mylist_2.contains(it.getIngrCode()+it.getTargetIngrCode()) && !mylist_2.contains(it.getTargetIngrCode()+it.getIngrCode()) && !it.getIngrCode().equals(it.getTargetIngrCode())) {
                        mylist_2.add(it.getIngrCode()+it.getTargetIngrCode());
                        ingrAndIngrList_new.add(it);
                    }
                }
                ingrAndIngrList = ingrAndIngrList_new;
            }
            // ingr-dis
            else if(isIngrDisease){
                //获取ingr列表
                List<String> ingr_list = new ArrayList<>();
                for (String key : reqVo.getTargetName())
                    ingr_list.add(key);
                //查询ingr-ingr
                QueryWrapper<EtcmIngrIngrPo> ingrWrapper = new QueryWrapper<>();
                int count = ingr_list.size();
                ingrWrapper.in(!CollectionUtils.isEmpty(ingr_list),"C.ingr_code",ingr_list)
                        .in(!CollectionUtils.isEmpty(ingr_list),"C.target_ingr_code",ingr_list)
                        .isNotNull("C.ingr_ingr_distance")
                        .gt("C.ingr_ingr_distance",0)
                        .last("limit "+String.valueOf(count*(count-1)/2));
                ingrAndIngrList = etcmPxExMapper.getIngrAndIngrByIngrID(ingrWrapper);
                List<String> mylist_2=new ArrayList<>();
                List<EtcmIngrIngrPo> ingrAndIngrList_new= new ArrayList<>();
                for(EtcmIngrIngrPo it:ingrAndIngrList){
                    if (!mylist_2.contains(it.getIngrCode()+it.getTargetIngrCode()) && !mylist_2.contains(it.getTargetIngrCode()+it.getIngrCode()) && !it.getIngrCode().equals(it.getTargetIngrCode())) {
                        mylist_2.add(it.getIngrCode()+it.getTargetIngrCode());
                        ingrAndIngrList_new.add(it);
                    }
                }
                ingrAndIngrList = ingrAndIngrList_new;
            }
            //herb-herb ingr-ingr未进入
            else {
                //生成草药列表
                List<String> herb_list = new ArrayList<>();
//                for (String key : reqVo.getSourceName().keySet())
                herb_list.add(reqVo.getSourceName());
                for (String key : reqVo.getTargetName())
                    herb_list.add(key);
                //查找成分列表
                QueryWrapper<EtcmIngrPo> ingrIDWrapper = new QueryWrapper<>();
                ingrIDWrapper.in(!CollectionUtils.isEmpty(herb_list),"herb_id",herb_list);
                List<EtcmIngrPo> etcmIngrPolist = etcmPxExMapper.getIngrID(ingrIDWrapper);
                List<String> ingrIDlist = new ArrayList<>();
                for(EtcmIngrPo it:etcmIngrPolist){
                    ingrIDlist.add(it.getIngrCode());
                }

                //查找ingr-ingr关系对
                QueryWrapper<EtcmIngrIngrPo> ingrWrapper = new QueryWrapper<>();
                ingrWrapper.in(!CollectionUtils.isEmpty(ingrIDlist),"C.ingr_code",ingrIDlist);
                ingrWrapper.in(!CollectionUtils.isEmpty(ingrIDlist),"C.target_ingr_code",ingrIDlist);
                ingrWrapper.isNotNull("C.ingr_ingr_distance");
                ingrWrapper.gt("C.ingr_ingr_distance",'0');
                ingrWrapper.last("limit 200");
                ingrAndIngrList = etcmPxExMapper.getIngrAndIngrByIngrID(ingrWrapper);
                List<String> mylist_2=new ArrayList<>();
                List<EtcmIngrIngrPo> ingrAndIngrList_new= new ArrayList<>();
                for(EtcmIngrIngrPo it:ingrAndIngrList){
                    if (!mylist_2.contains(it.getIngrCode()+it.getTargetIngrCode()) && !mylist_2.contains(it.getTargetIngrCode()+it.getIngrCode()) && !it.getIngrCode().equals(it.getTargetIngrCode())) {
                        mylist_2.add(it.getIngrCode()+it.getTargetIngrCode());
                        ingrAndIngrList_new.add(it);
                    }
                }
                ingrAndIngrList = ingrAndIngrList_new;
                System.out.println("################ingringr############");
            }
        }


        List<EtcmHerbDiseasePo> herbAndDiseaseList = new ArrayList<>();
        List<EtcmHerbDiseasePo> herbAndDiseaseListRes =  new ArrayList<>();
        List<EtcmHerbDiseasePo> herbAndDiseaseListNew = new ArrayList<>();
        if (isHerbDisease){
            if(isPxHerb){
                QueryWrapper<EtcmHerbDiseasePo> herbAndDiseaseWrapper = new QueryWrapper<>();
                //herbAndDiseaseWrapper.isNotNull("t1.id");
                //herbAndDiseaseWrapper.orderByDesc("t1.herb_disease_distance");

                //获取herb列表
                List<String> herbidlist = new ArrayList<>();
                for(EtcmPxHerbPo it:pxAndHerbList){
                    if(!herbidlist.contains(it.getHerbId()))
                        herbidlist.add(it.getHerbId());
                }
                //查询herb-disease
                String diseaseid = reqVo.getSourceName();
//                for (String it:.keySet()){
//                    diseaseid=;
//                    break;
//                }
                herbAndDiseaseWrapper.in(!CollectionUtils.isEmpty(herbidlist),"C.herb_id",herbidlist);
                herbAndDiseaseWrapper.eq("C.disease_id",diseaseid);
                herbAndDiseaseWrapper.isNotNull("C.herb_disease_distance");
                herbAndDiseaseWrapper.gt("C.herb_disease_distance",0);
                herbAndDiseaseWrapper.last("limit "+String.valueOf(herbidlist.size()));
                herbAndDiseaseList = etcmPxExMapper.getHerbAndDiseaseByHerbID(herbAndDiseaseWrapper);
            }
            else {
                QueryWrapper<EtcmHerbDiseasePo> herbAndDiseaseWrapper = new QueryWrapper<>();
                //herbAndDiseaseWrapper.isNotNull("t1.id");
                //herbAndDiseaseWrapper.orderByDesc("t1.herb_disease_distance");

                //获取herb列表
//                List<String> herb_list = new ArrayList<>();
//                for (String key : reqVo.getSourceName().keySet())
//                    herb_list.add(key);
                //查询herb-disease
                herbAndDiseaseWrapper.in("C.herb_id",reqVo.getTargetName());
                herbAndDiseaseWrapper.eq("C.disease_id",reqVo.getSourceName());
                herbAndDiseaseWrapper.isNotNull("C.herb_disease_distance");
                herbAndDiseaseWrapper.gt("C.herb_disease_distance",0);
                herbAndDiseaseWrapper.last("limit "+String.valueOf(reqVo.getTargetName().size()));
                herbAndDiseaseList = etcmPxExMapper.getHerbAndDiseaseByHerbID(herbAndDiseaseWrapper);
            }
        }



        List<EtcmIngrDiseasePo> ingrAndDiseaseList = new ArrayList<>();
        List<EtcmIngrDiseasePo> ingrAndDiseaseListRes = new ArrayList<>();
        List<EtcmIngrDiseasePo> ingrAndDiseaseListNew = new ArrayList<>();
        if (isIngrDisease){
            //px-dis herb-dis
            if(isPxHerb || isHerbDisease){
                //获取ingr列表
                List<String> ingridlist = new ArrayList<>();
                for(HerbIngrVo it:herbAndIngrList){
                    if(!ingridlist.contains(it.getIngrId()))
                        ingridlist.add(it.getIngrId());
                }
                //查询ingr-disease
                QueryWrapper<EtcmIngrDiseasePo> ingrAndDiseaseWrapper = new QueryWrapper<>();
//                ingrAndDiseaseWrapper.isNotNull("t1.id");
                //ingrAndDiseaseWrapper.orderByDesc("t1.ingr_disease_distance");
//                for (String it:reqVo.getSourceName().keySet()){
//                    diseaseid=it;
//                    break;
//                }
                ingrAndDiseaseWrapper.in(!CollectionUtils.isEmpty(ingridlist),"C.ingr_id",ingridlist);
                ingrAndDiseaseWrapper.eq("C.disease_id",reqVo.getSourceName());
                ingrAndDiseaseWrapper.isNotNull("C.ingr_disease_distance");
                ingrAndDiseaseWrapper.gt("C.ingr_disease_distance",0);
                ingrAndDiseaseWrapper.last("limit "+String.valueOf(ingridlist.size()));
                ingrAndDiseaseList = etcmPxExMapper.getIngrAndDiseaseByIngrID(ingrAndDiseaseWrapper);
            }
            //ingr-dis
            else {
                //获取ingr列表
//                List<String> ingr_list = new ArrayList<>();
//                for (String key : reqVo.getSourceName().keySet())
//                    ingr_list.add(key);
                //查询ingr-disease
                QueryWrapper<EtcmIngrDiseasePo> ingrAndDiseaseWrapper = new QueryWrapper<>();
//                ingrAndDiseaseWrapper.isNotNull("t1.id");
                //ingrAndDiseaseWrapper.orderByDesc("t1.ingr_disease_distance");
                ingrAndDiseaseWrapper.in("C.ingr_id",reqVo.getTargetName());
                ingrAndDiseaseWrapper.eq("C.disease_id",reqVo.getSourceName());
                ingrAndDiseaseWrapper.isNotNull("C.ingr_disease_distance");
                ingrAndDiseaseWrapper.gt("C.ingr_disease_distance",0);
                ingrAndDiseaseWrapper.last("limit "+ String.valueOf(reqVo.getTargetName().size()));
                ingrAndDiseaseList = etcmPxExMapper.getIngrAndDiseaseByIngrID(ingrAndDiseaseWrapper);
            }

        }

        if (numberType == CommonConsts.STATUS_DEL){
            List<EtcmUiElPo> uiElNameList = etcmPxExMapper.getUIElName(reqVo.getUiTypeCode(), reqVo.getLangCode());
            PageModel<Map<String, String>> page = getNetworkTablePage(
                    reqVo.getLangCode(),
                    !reqVo.getTargetName().isEmpty() ? pxAndDiseaseListRes : (!reqVo.getSourceName().isEmpty() ? pxAndDiseaseListNew : pxAndDiseaseList),
                    !herbAndDiseaseList.isEmpty() ? herbAndDiseaseList : (!reqVo.getSourceName().isEmpty() ? herbAndDiseaseListNew : herbAndDiseaseList),
                    !ingrAndDiseaseList.isEmpty() ? ingrAndDiseaseList : (!reqVo.getSourceName().isEmpty() ? ingrAndDiseaseListNew : ingrAndDiseaseList),
                    !pxAndHerbList.isEmpty() ? pxAndHerbList : (!reqVo.getSourceName().isEmpty() ? pxAndHerbListNew : pxAndHerbList),
                    !herbAndHerbList.isEmpty() ? herbAndHerbList : herbAndHerbList,
                    !ingrAndIngrList.isEmpty() ? ingrAndIngrList : ingrAndIngrList,
                    !herbAndIngrList.isEmpty() ? herbAndIngrList : herbAndIngrList,
                    uiElNameList,
                    reqVo.getPageNo(),
                    reqVo.getPageSize());
            PxNetworkStatisticsRespVo vo = new PxNetworkStatisticsRespVo();
            vo.setTableList(page);
            return new ResultModel<PxNetworkStatisticsRespVo>().success(vo);
        }

        if (numberType == CommonConsts.STATUS_NORMAL){
            PxNetworkStatisticsRespVo vo = getPxNetworkStatisticsRespVoResultModel(
                    reqVo.getLangCode(),
                    !reqVo.getTargetName().isEmpty() ? pxAndDiseaseListRes : (!reqVo.getSourceName().isEmpty() ? pxAndDiseaseListNew : pxAndDiseaseList),
                    !herbAndDiseaseList.isEmpty() ? herbAndDiseaseList : (!reqVo.getSourceName().isEmpty() ? herbAndDiseaseListNew : herbAndDiseaseList),
                    !ingrAndDiseaseList.isEmpty() ? ingrAndDiseaseList : (!reqVo.getSourceName().isEmpty() ? ingrAndDiseaseListNew : ingrAndDiseaseList),
                    !pxAndHerbList.isEmpty() ? pxAndHerbList : (!reqVo.getSourceName().isEmpty() ? pxAndHerbListNew : pxAndHerbList),
                    !herbAndHerbList.isEmpty() ? herbAndHerbList : herbAndHerbList,
                    !ingrAndIngrList.isEmpty() ? ingrAndIngrList : ingrAndIngrList,
                    !herbAndIngrList.isEmpty() ? herbAndIngrList : herbAndIngrList);
            PxNetworkStatisticsRespVo res = new PxNetworkStatisticsRespVo();
            res.setScatterDiagram(vo.getScatterDiagram());
            return new ResultModel<PxNetworkStatisticsRespVo>().success(res);
        }

        return null;

    }

    /**
     *
     * @param reqVo
     * @param isPxDisease
     * @param isHerbDisease
     * @param isIngrDisease
     * @param isPxHerb
     * @param isHerbHerb
     * @param isIngrIngr
     * @param isHerbIngr
     * @param numberType 数据类型 1.散点图 2.table表格
     * @param combinType 组合类型 1.herb-herb 2.ingr-ingr 3.px-disease 4.herb-disease 5.ingr-disease
     * @return
     */
    @Override
    public ResultModel<PxNetworkStatisticsRespVo> getNetworkTwo(HerbHerbPageReqVo reqVo,boolean isPxDisease,boolean isHerbDisease,boolean isIngrDisease,boolean isPxHerb,boolean isHerbHerb,boolean isIngrIngr,boolean isHerbIngr,int numberType,int combinType){
        if(StringUtils.isBlank(reqVo.getSourceName()) || CollectionUtils.isEmpty(reqVo.getTargetName())){
            return new ResultModel<PxNetworkStatisticsRespVo>().failure("请添加条件");
        }
        String redisKey = reqVo.getSourceName();
        for (String targetCode : reqVo.getTargetName()) {
            redisKey = redisKey + "-" + targetCode;
        }
        switch (combinType){
            case CombinConsts.HERB_HERB:
                redisKey = CombinConsts.COMBIN_HERB_HERB +redisKey;
                break;
            case CombinConsts.INGR_INGR:
                redisKey = CombinConsts.COMBIN_INGR_INGR +redisKey;
                break;
            case CombinConsts.PX_DISEASE:
                redisKey = CombinConsts.COMBIN_PX_DISEASE +redisKey;
                break;
            case CombinConsts.HERB_DISEASE:
                redisKey = CombinConsts.COMBIN_HERB_DISEASE +redisKey;
                break;
            case CombinConsts.INGR_DISEASE:
                redisKey = CombinConsts.COMBIN_INGR_DISEASE +redisKey;
            default:
        }

        List<EtcmPxHerbPo> pxHerbList = null;
        List<EtcmHerbHerbPo> herbHerbList = null;
        List<HerbIngrVo> herbIngrList = null;
        List<EtcmIngrIngrPo> ingrIngrList = null;
        List<EtcmIngrDiseasePo> ingrDiseaseList = null;
        List<EtcmHerbDiseasePo> herbDiseaseList = null;
        List<PxDiseaseRespVo> pxDiseaseList = null;

        if (redisUtils.hasKey(redisKey)){
            switch (combinType){
                case CombinConsts.HERB_HERB:
                    HerbHerbRedisRespVo res = (HerbHerbRedisRespVo) redisUtils.get(redisKey);
                    herbHerbList = res.getHerbHerbList();
                    herbIngrList = res.getHerbIngrList();
                    ingrIngrList = res.getIngrIngrList();
                    break;
                case CombinConsts.INGR_INGR:
                    IngrIngrRedisRespVo ingrIngrVo = (IngrIngrRedisRespVo) redisUtils.get(redisKey);
                    ingrIngrList = ingrIngrVo.getIngrIngrList();
                    break;
                case CombinConsts.PX_DISEASE:
                    PxDiseaseRedisRespVo pxDiseaseRespVo = (PxDiseaseRedisRespVo) redisUtils.get(redisKey);
                    pxDiseaseList = pxDiseaseRespVo.getPxDiseaseList();
                    herbDiseaseList = pxDiseaseRespVo.getHerbDiseaseList();
                    ingrDiseaseList = pxDiseaseRespVo.getIngrDiseaseList();
                    herbIngrList = pxDiseaseRespVo.getHerbIngrList();
                    herbHerbList = pxDiseaseRespVo.getHerbHerbList();
                    ingrIngrList = pxDiseaseRespVo.getIngrIngrList();
                    break;
                case CombinConsts.HERB_DISEASE:
                    HerbDiseaseRedisRespVo herbDiseaseRespVo = (HerbDiseaseRedisRespVo) redisUtils.get(redisKey);
                    herbDiseaseList = herbDiseaseRespVo.getHerbDiseaseList();
                    ingrDiseaseList = herbDiseaseRespVo.getIngrDiseaseList();
                    herbIngrList = herbDiseaseRespVo.getHerbIngrList();
                    herbHerbList = herbDiseaseRespVo.getHerbHerbList();
                    ingrIngrList = herbDiseaseRespVo.getIngrIngrList();
                    break;
                case CombinConsts.INGR_DISEASE:

                    IngrDiseaseRedisRespVo ingrDiseaseRespVo = (IngrDiseaseRedisRespVo) redisUtils.get(redisKey);
                    ingrDiseaseList = ingrDiseaseRespVo.getIngrDiseaseList();
                    ingrIngrList = ingrDiseaseRespVo.getIngrIngrList();
                default:
            }

        }else {
            List<String> herbCodeByPxDiseaseList = null;
            List<String> herbCodeByHerbDiseaseList = null;
            List<String> ingrCodeByHerbHerb = null;
            List<String> ingrCodeByPxDiseaseList = null;
            List<String> ingrCodeByHerbDiseaseList = null;
            List<String> ingrCodeByIngrDiseaseList = null;
            List<String> diseaseCodeByPxDiseaseList = null;
            List<String> diseaseCodeByHerbDiseaseList = null;



            switch (combinType){
                case CombinConsts.HERB_HERB:
                    reqVo.getTargetName().add(reqVo.getSourceName());
                    List<String> collect = reqVo.getTargetName().stream().distinct().collect(Collectors.toList());
                    ingrCodeByHerbHerb = etcmDiseaseMapper.getIngrCodeByHerbHerb(collect);
                    break;
                case CombinConsts.INGR_INGR:
                    break;
                case CombinConsts.PX_DISEASE:

                    herbCodeByPxDiseaseList = etcmDiseaseMapper.getHerbCodeByPxDiseaseList(reqVo.getSourceName(),reqVo.getTargetName());
                    ingrCodeByPxDiseaseList = etcmDiseaseMapper.getIngrCodeByPxDiseaseList(reqVo.getSourceName(),reqVo.getTargetName());
                    diseaseCodeByPxDiseaseList = etcmDiseaseMapper.getDiseaseCodeByPxDiseaseList(reqVo.getSourceName(),reqVo.getTargetName());
                    break;
                case CombinConsts.HERB_DISEASE:
                    herbCodeByHerbDiseaseList = etcmDiseaseMapper.getHerbCodeByHerbDiseaseList(reqVo.getSourceName(),reqVo.getTargetName());
                    ingrCodeByHerbDiseaseList = etcmDiseaseMapper.getIngrCodeByHerbDiseaseList(reqVo.getSourceName(),reqVo.getTargetName());
                    diseaseCodeByHerbDiseaseList = etcmDiseaseMapper.getDiseaseCodeByHerbDiseaseList(reqVo.getSourceName(),reqVo.getTargetName());
                    break;
                case CombinConsts.INGR_DISEASE:

                    ingrCodeByIngrDiseaseList = etcmDiseaseMapper.getIngrCodeByIngrDisease(reqVo.getSourceName(),reqVo.getTargetName());

                default:
            }


            if (isHerbHerb){
                QueryWrapper<EtcmHerbHerbPo> herbWrapper = new QueryWrapper<>();
                herbWrapper.isNotNull("t1.herb_herb_distance");
                herbWrapper.gt("t1.herb_herb_distance",0);
                //herbWrapper.orderByAsc("t1.herb_herb_distance");
                herbWrapper.last("limit 200");
                if (CombinConsts.HERB_HERB == combinType){
                    herbWrapper.eq("t1.herb_code",reqVo.getSourceName());
                    herbWrapper.in("t1.target_herb_code",reqVo.getTargetName());
                    if (CollectionUtils.isNotEmpty(reqVo.getTargetName())) {
                        herbHerbList = etcmDiseaseMapper.getHerbAndHerb(herbWrapper);
                    }
                }
                if (CombinConsts.PX_DISEASE == combinType){
                    herbWrapper.in("t1.herb_code",herbCodeByPxDiseaseList);

                    if (CollectionUtils.isNotEmpty(herbCodeByPxDiseaseList)){
                        herbHerbList = etcmDiseaseMapper.getHerbAndHerb(herbWrapper);
                    }
                }

                if (CombinConsts.HERB_DISEASE == combinType){
                    herbWrapper.in("t1.herb_code",herbCodeByHerbDiseaseList);
                    if (CollectionUtils.isNotEmpty(herbCodeByHerbDiseaseList)){
                        herbHerbList = etcmDiseaseMapper.getHerbAndHerb(herbWrapper);
                    }
                }




            }

            if (isIngrIngr){
                QueryWrapper<EtcmIngrIngrPo> ingrWrapper = new QueryWrapper<>();
                ingrWrapper.isNotNull("t1.ingr_ingr_distance");
                ingrWrapper.gt("t1.ingr_ingr_distance",0);
                //ingrWrapper.orderByAsc("t1.ingr_ingr_distance");
                ingrWrapper.last("limit 200");
                if (CombinConsts.HERB_HERB == combinType){
                    ingrWrapper.in("t1.ingr_code",ingrCodeByHerbHerb);
                    if (CollectionUtils.isNotEmpty(ingrCodeByHerbHerb)){
                        ingrIngrList = etcmDiseaseMapper.getIngrAndIngr(ingrWrapper);
                    }
                }
                if (CombinConsts.INGR_INGR == combinType){
                    ingrWrapper.eq("t1.ingr_code",reqVo.getSourceName());
                    ingrWrapper.in("t1.target_ingr_code",reqVo.getTargetName());
                    if (CollectionUtils.isNotEmpty(reqVo.getTargetName())){
                        ingrIngrList = etcmDiseaseMapper.getIngrAndIngr(ingrWrapper);
                    }
                }
                if (CombinConsts.PX_DISEASE == combinType){
                    ingrWrapper.in("t1.ingr_code",ingrCodeByPxDiseaseList);
                    if (CollectionUtils.isNotEmpty(ingrCodeByPxDiseaseList)){
                        ingrIngrList = etcmDiseaseMapper.getIngrAndIngr(ingrWrapper);
                    }
                }
                if (CombinConsts.HERB_DISEASE == combinType){
                    ingrWrapper.in("t1.ingr_code",ingrCodeByHerbDiseaseList);
                    if (CollectionUtils.isNotEmpty(ingrCodeByHerbDiseaseList)){
                        ingrIngrList = etcmDiseaseMapper.getIngrAndIngr(ingrWrapper);
                    }
                }
                if (CombinConsts.INGR_DISEASE == combinType){
                    ingrWrapper.in("t1.ingr_code",ingrCodeByIngrDiseaseList);
                    if (CollectionUtils.isNotEmpty(ingrCodeByIngrDiseaseList)){
                        ingrIngrList = etcmDiseaseMapper.getIngrAndIngr(ingrWrapper);
                    }
                }


            }

            if (isPxDisease){
                QueryWrapper<PxDiseaseRespVo> herbDiseaseWrapper = new QueryWrapper<>();
                herbDiseaseWrapper.eq("t1.disease_id",reqVo.getSourceName());
                //herbDiseaseWrapper.in("t1.px_id",reqVo.getTargetName());


                herbDiseaseWrapper.isNotNull("t1.herb_disease_distance");
                herbDiseaseWrapper.gt("t1.herb_disease_distance",0);
                herbDiseaseWrapper.last("limit 200");
                if (CollectionUtils.isNotEmpty(reqVo.getTargetName())){
                    pxDiseaseList = etcmDiseaseMapper.getPxAndDisease(herbDiseaseWrapper,reqVo.getTargetName());
                }
            }

            if (isHerbDisease){
                QueryWrapper<EtcmHerbDiseasePo> herbDiseaseWrapper = new QueryWrapper<>();
                herbDiseaseWrapper.isNotNull("t1.herb_disease_distance");
                herbDiseaseWrapper.gt("t1.herb_disease_distance",0);
                //herbDiseaseWrapper.orderByAsc("t1.herb_disease_distance");
                herbDiseaseWrapper.last("limit 200");

                if (CombinConsts.PX_DISEASE == combinType){
                    herbDiseaseWrapper.in("t1.disease_id",diseaseCodeByPxDiseaseList);
                    if(CollectionUtils.isNotEmpty(diseaseCodeByPxDiseaseList)){
                        herbDiseaseList = etcmDiseaseMapper.getHerbAndDisease(herbDiseaseWrapper);
                    }
                }
                if (CombinConsts.HERB_DISEASE == combinType){
                    herbDiseaseWrapper.eq("t1.disease_id",reqVo.getSourceName());
                    herbDiseaseWrapper.in("t1.herb_id",reqVo.getTargetName());
                    if (CollectionUtils.isNotEmpty(reqVo.getTargetName())){
                        herbDiseaseList = etcmDiseaseMapper.getHerbAndDisease(herbDiseaseWrapper);
                    }
                }


            }

            if (isIngrDisease){
                QueryWrapper<EtcmIngrDiseasePo> ingrDiseaseWrapper = new QueryWrapper<>();
                ingrDiseaseWrapper.isNotNull("t1.ingr_disease_distance");
                ingrDiseaseWrapper.gt("t1.ingr_disease_distance",0);
                //ingrDiseaseWrapper.orderByAsc("t1.ingr_disease_distance");
                ingrDiseaseWrapper.last("limit 200");
                if (CombinConsts.PX_DISEASE == combinType){
                    ingrDiseaseWrapper.in("t1.disease_id",diseaseCodeByPxDiseaseList);
                    if(CollectionUtils.isNotEmpty(diseaseCodeByPxDiseaseList)){
                        ingrDiseaseList = etcmDiseaseMapper.getIngrAndDisease(ingrDiseaseWrapper);
                    }
                }
                if (CombinConsts.HERB_DISEASE == combinType){
                    ingrDiseaseWrapper.eq("t1.disease_id",diseaseCodeByHerbDiseaseList);
                    if(CollectionUtils.isNotEmpty(diseaseCodeByHerbDiseaseList)){
                        ingrDiseaseList = etcmDiseaseMapper.getIngrAndDisease(ingrDiseaseWrapper);
                    }
                }
                if (CombinConsts.INGR_DISEASE == combinType){
                    ingrDiseaseWrapper.eq("t1.disease_id",reqVo.getSourceName());
                    ingrDiseaseWrapper.in("t1.ingr_id",reqVo.getTargetName());
                    if(CollectionUtils.isNotEmpty(reqVo.getTargetName())){
                        ingrDiseaseList = etcmDiseaseMapper.getIngrAndDisease(ingrDiseaseWrapper);
                    }
                }


            }

            if (isPxHerb){

            }

            if (isHerbIngr){
                QueryWrapper<HerbIngrVo> herbIngrWrapper = new QueryWrapper<>();
                herbIngrWrapper.isNotNull("t1.herb_ingr_distance");
                herbIngrWrapper.gt("t1.herb_ingr_distance",0);
                //herbIngrWrapper.orderByAsc("t1.herb_ingr_distance");
                herbIngrWrapper.last("limit 200");
                if (CombinConsts.HERB_HERB == combinType){
                    reqVo.getTargetName().add(reqVo.getSourceName());
                    List<String> collect = reqVo.getTargetName().stream().distinct().collect(Collectors.toList());
                    herbIngrWrapper.in("t1.herb_id",collect);
                    if (CollectionUtils.isNotEmpty(collect)){
                        herbIngrList = etcmDiseaseMapper.getHerbAndIngr(herbIngrWrapper);
                    }

                }
                if (CombinConsts.PX_DISEASE == combinType){

                    herbIngrWrapper.in("t1.herb_id",herbCodeByPxDiseaseList);
                    if (CollectionUtils.isNotEmpty(herbCodeByPxDiseaseList)){
                        herbIngrList = etcmDiseaseMapper.getHerbAndIngr(herbIngrWrapper);
                    }

                }
                if (CombinConsts.HERB_DISEASE == combinType){
                    herbIngrWrapper.in("t1.herb_id",herbCodeByHerbDiseaseList);
                    if (CollectionUtils.isNotEmpty(herbCodeByHerbDiseaseList)){
                        herbIngrList = etcmDiseaseMapper.getHerbAndIngr(herbIngrWrapper);
                    }
                }


            }

            switch (combinType){
                case CombinConsts.HERB_HERB:
                    HerbHerbRedisRespVo herbHerbRedisRespVo = new HerbHerbRedisRespVo();
                    herbHerbRedisRespVo.setHerbHerbList(herbHerbList);
                    herbHerbRedisRespVo.setHerbIngrList(herbIngrList);
                    herbHerbRedisRespVo.setIngrIngrList(ingrIngrList);

                    redisUtils.set(redisKey,herbHerbRedisRespVo);

                    break;
                case CombinConsts.INGR_INGR:
                    IngrIngrRedisRespVo ingrIngrRedisRespVo = new IngrIngrRedisRespVo();
                    ingrIngrRedisRespVo.setIngrIngrList(ingrIngrList);
                    redisUtils.set(redisKey,ingrIngrRedisRespVo);
                    break;
                case CombinConsts.PX_DISEASE:
                    PxDiseaseRedisRespVo pxDiseaseRespVo = new PxDiseaseRedisRespVo();
                    pxDiseaseRespVo.setPxDiseaseList(pxDiseaseList);
                    pxDiseaseRespVo.setHerbDiseaseList(herbDiseaseList);
                    pxDiseaseRespVo.setIngrDiseaseList(ingrDiseaseList);
                    pxDiseaseRespVo.setHerbHerbList(herbHerbList);
                    pxDiseaseRespVo.setHerbIngrList(herbIngrList);
                    pxDiseaseRespVo.setIngrIngrList(ingrIngrList);
                    redisUtils.set(redisKey,pxDiseaseRespVo);
                case CombinConsts.HERB_DISEASE:
                    HerbDiseaseRedisRespVo herbDiseaseRespVo = new HerbDiseaseRedisRespVo();
                    herbDiseaseRespVo.setHerbDiseaseList(herbDiseaseList);
                    herbDiseaseRespVo.setIngrDiseaseList(ingrDiseaseList);
                    herbDiseaseRespVo.setHerbHerbList(herbHerbList);
                    herbDiseaseRespVo.setHerbIngrList(herbIngrList);
                    herbDiseaseRespVo.setIngrIngrList(ingrIngrList);
                    redisUtils.set(redisKey,herbDiseaseRespVo);
                case CombinConsts.INGR_DISEASE:
                    IngrDiseaseRedisRespVo ingrDiseaseRespVo = new IngrDiseaseRedisRespVo();
                    ingrDiseaseRespVo.setIngrIngrList(ingrIngrList);
                    ingrDiseaseRespVo.setIngrDiseaseList(ingrDiseaseList);
                    redisUtils.set(redisKey,ingrDiseaseRespVo);
                default:
            }

        }




        if (numberType == CommonConsts.STATUS_DEL){
            List<EtcmUiElPo> uiElNameList = etcmPxExMapper.getUIElName(reqVo.getUiTypeCode(), reqVo.getLangCode());
            PageModel<Map<String, String>> page = getNetworkTablePage(
                    reqVo.getLangCode(),
                    pxDiseaseList,
                    herbDiseaseList,
                    ingrDiseaseList,
                    null,
                    herbHerbList,
                    ingrIngrList,
                    herbIngrList,
                    uiElNameList,
                    reqVo.getPageNo(),
                    reqVo.getPageSize());
            PxNetworkStatisticsRespVo vo = new PxNetworkStatisticsRespVo();
            vo.setTableList(page);
            return new ResultModel<PxNetworkStatisticsRespVo>().success(vo);
        }

        if (numberType == CommonConsts.STATUS_NORMAL){
            PxNetworkStatisticsRespVo vo = getPxNetworkStatisticsRespVoResultModel(
                    reqVo.getLangCode(),
                    pxDiseaseList,
                    herbDiseaseList,
                    ingrDiseaseList,
                    null,
                    herbHerbList,
                    ingrIngrList,
                    herbIngrList);
            PxNetworkStatisticsRespVo res = new PxNetworkStatisticsRespVo();
            res.setScatterDiagram(vo.getScatterDiagram());
            return new ResultModel<PxNetworkStatisticsRespVo>().success(res);
        }

        return null;

    }

    @Override
    public ResultModel<PxNetworkStatisticsRespVo> getNetwork_ingr_ingr(HerbHerbPageReqVo reqVo,int numberType){
        List<EtcmIngrIngrPo> ingrAndIngrList = null;
        //生成成分列表
        List<String> ingr_list = new ArrayList<>();
        //for (String key : reqVo.getSourceName().keySet())
        ingr_list.add(reqVo.getSourceName());
        for (String key : reqVo.getTargetName())
            ingr_list.add(key);
        //查找ingr-ingr关系对
        int count = ingr_list.size();
        QueryWrapper<EtcmIngrIngrPo> ingrWrapper = new QueryWrapper<>();
        ingrWrapper.in(!CollectionUtils.isEmpty(ingr_list),"C.ingr_code",ingr_list)
                .in(!CollectionUtils.isEmpty(ingr_list),"C.target_ingr_code",ingr_list)
                .isNotNull("C.ingr_ingr_distance")
                .gt("C.ingr_ingr_distance",0)
                .last("limit "+String.valueOf(count*(count-1)/2));
        ingrAndIngrList = etcmPxExMapper.getIngrAndIngrByIngrID(ingrWrapper);
        List<String> mylist_2=new ArrayList<>();
        List<EtcmIngrIngrPo> ingrAndIngrList_new= new ArrayList<>();
        for(EtcmIngrIngrPo it:ingrAndIngrList){
            if (!mylist_2.contains(it.getIngrCode()+it.getTargetIngrCode()) && !mylist_2.contains(it.getTargetIngrCode()+it.getIngrCode()) && !it.getIngrCode().equals(it.getTargetIngrCode())) {
                mylist_2.add(it.getIngrCode()+it.getTargetIngrCode());
                ingrAndIngrList_new.add(it);
            }
        }
        ingrAndIngrList = ingrAndIngrList_new;

        if (numberType == CommonConsts.STATUS_DEL){
            List<EtcmUiElPo> uiElNameList = etcmPxExMapper.getUIElName(reqVo.getUiTypeCode(), reqVo.getLangCode());
            PageModel<Map<String, String>> page = getNetworkTablePage(
                    reqVo.getLangCode(),
                    null,
                    null,
                    null,
                    null,
                    null,
                    !ingrAndIngrList.isEmpty() ? ingrAndIngrList : null,
                    null,
                    uiElNameList,
                    reqVo.getPageNo(),
                    reqVo.getPageSize());
            PxNetworkStatisticsRespVo vo = new PxNetworkStatisticsRespVo();
            vo.setTableList(page);
            return new ResultModel<PxNetworkStatisticsRespVo>().success(vo);
        }

        if (numberType == CommonConsts.STATUS_NORMAL){
            PxNetworkStatisticsRespVo vo = getPxNetworkStatisticsRespVoResultModel(
                    reqVo.getLangCode(),
                    null,
                    null,
                    null,
                    null,
                    null,
                    !ingrAndIngrList.isEmpty() ? ingrAndIngrList : null,
                    null);
            PxNetworkStatisticsRespVo res = new PxNetworkStatisticsRespVo();
            res.setScatterDiagram(vo.getScatterDiagram());
            return new ResultModel<PxNetworkStatisticsRespVo>().success(res);
        }


        return null;
    }

    @Override
    public PageModel<Map<String,String>> getNetworkTablePage(String langCode, List<PxDiseaseRespVo> pxAndDiseaseList, List<EtcmHerbDiseasePo> herbAndDiseaseList, List<EtcmIngrDiseasePo> ingrAndDiseaseList, List<EtcmPxHerbPo> pxAndHerbList, List<EtcmHerbHerbPo> herbAndHerbList, List<EtcmIngrIngrPo> ingrAndIngrList, List<HerbIngrVo> herbAndIngrList, List<EtcmUiElPo> uiElNameList, Integer pageNo, Integer pageSize){
        if (null == pageNo){
            pageNo = 1;
        }
        if (null == pageSize){
            pageNo = 10;
        }
        Set<Map<String,String>> tableList = new HashSet<>();
        if (!CollectionUtils.isEmpty(pxAndDiseaseList)){
            pxAndDiseaseList.forEach(pxAndDisease -> {
                Map<String, String> map = getStringStringMap(langCode, pxAndDisease, uiElNameList);
                tableList.add(map);
            });
        }
        if (!CollectionUtils.isEmpty(herbAndDiseaseList)){
            herbAndDiseaseList.forEach(herbDiseasePo -> {
                Map<String, String> map = getStringStringMap(langCode, herbDiseasePo, uiElNameList);
                tableList.add(map);
            });
        }
        if (!CollectionUtils.isEmpty(ingrAndDiseaseList)){
            ingrAndDiseaseList.forEach(etcmIngrDiseasePo -> {
                Map<String, String> map = getStringStringMap(langCode, etcmIngrDiseasePo, uiElNameList);
                tableList.add(map);
            });
        }
        if (!CollectionUtils.isEmpty(pxAndHerbList)){
            pxAndHerbList.forEach(etcmPxHerbPo -> {
                Map<String, String> map = getStringStringMap(langCode, etcmPxHerbPo, uiElNameList);
                tableList.add(map);
            });
        }
        if (!CollectionUtils.isEmpty(herbAndHerbList)){
            herbAndHerbList.forEach(etcmHerbHerbPo -> {
                Map<String, String> map = getStringStringMap(langCode, etcmHerbHerbPo, uiElNameList);
                tableList.add(map);
            });
        }
        if (!CollectionUtils.isEmpty(ingrAndIngrList)){
            ingrAndIngrList.forEach(etcmIngrIngrPo -> {
                Map<String, String> map = getStringStringMap(langCode, etcmIngrIngrPo, uiElNameList);
                tableList.add(map);

            });
        }
        if (!CollectionUtils.isEmpty(herbAndIngrList)){
            herbAndIngrList.forEach(herbIngrVo -> {
                Map<String, String> map = getStringStringMap(langCode, herbIngrVo, uiElNameList);
                tableList.add(map);

            });
        }

        List<Map<String, String>> collect = tableList.stream().skip((pageNo - 1) * pageSize).limit(pageSize).
                collect(Collectors.toList());

        PageModel<Map<String,String>> page=new PageModel<>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        page.setRecords(collect);
        page.setTotalCount(tableList.size());

        return page;
    }

    @Override
    public PxNetworkStatisticsRespVo getPxNetworkStatisticsRespVoResultModel(String langCode, List<PxDiseaseRespVo> pxAndDiseaseList, List<EtcmHerbDiseasePo> herbAndDiseaseList, List<EtcmIngrDiseasePo> ingrAndDiseaseList, List<EtcmPxHerbPo> pxAndHerbList, List<EtcmHerbHerbPo> herbAndHerbList, List<EtcmIngrIngrPo> ingrAndIngrList, List<HerbIngrVo> herbAndIngrList) {
        PxNetworkStatisticsRespVo vo = new PxNetworkStatisticsRespVo();
        ScatterDiagram scatterDiagram = new ScatterDiagram();
        List<Relations> relationsList = new ArrayList<>();
        List<ResolutionNames> resolutionNamesList = new ArrayList<>();
        List<RelationsName> relationsNameList = new ArrayList<>();


        Map<String,String> herbNameMap = new HashMap<>(16);
        Map<String,String> ingrNameMap = new HashMap<>(16);
        Map<String,String> pxNameMap = new HashMap<>(16);
        Map<String,String> diseaseNameMap = new HashMap<>(16);


        if (!CollectionUtils.isEmpty(pxAndDiseaseList)){
            RelationsName relationsName = getRelationsName(langCode,"Prescription","Disease","处方","疾病",CommonConsts.PX,CommonConsts.DISEASE);
            relationsNameList.add(relationsName);


            pxAndDiseaseList.forEach(pxAndDisease -> {
                Relations relations = new Relations();
                relations.setSource(pxAndDisease.getPxId());
                relations.setTarget(pxAndDisease.getDiseaseId());
                relations.setDistance(pxAndDisease.getPxDiseaseDistance());
                relationsList.add(relations);


                if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                    pxNameMap.put(pxAndDisease.getPxId(),pxAndDisease.getPxEnName());
                    diseaseNameMap.put(pxAndDisease.getDiseaseId(),pxAndDisease.getDiseaseEnName());
                }

                if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                    pxNameMap.put(pxAndDisease.getPxId(),pxAndDisease.getPxZhName());
                    diseaseNameMap.put(pxAndDisease.getDiseaseId(),pxAndDisease.getDiseaseZhName());
                }


            });
        }
        if (!CollectionUtils.isEmpty(herbAndDiseaseList)){
            RelationsName relationsName = getRelationsName(langCode,"Herb","Disease","中草药","疾病",CommonConsts.HERB,CommonConsts.DISEASE);
            relationsNameList.add(relationsName);

            herbAndDiseaseList.forEach(herbDiseasePo -> {
                Relations relations = new Relations();
                relations.setSource(herbDiseasePo.getHerbId());
                relations.setTarget(herbDiseasePo.getDiseaseId());
                relations.setDistance(herbDiseasePo.getHerbDiseaseDistance());
                relationsList.add(relations);


                if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                    herbNameMap.put(herbDiseasePo.getHerbId(),herbDiseasePo.getHerbEnName());
                    diseaseNameMap.put(herbDiseasePo.getDiseaseId(),herbDiseasePo.getDiseaseEnName());
                }

                if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                    herbNameMap.put(herbDiseasePo.getHerbId(),herbDiseasePo.getHerbZhName());
                    diseaseNameMap.put(herbDiseasePo.getDiseaseId(),herbDiseasePo.getDiseaseZhName());
                }



            });
        }
        if (!CollectionUtils.isEmpty(ingrAndDiseaseList)){
            RelationsName relationsName = getRelationsName(langCode,"Ingredient","Disease","成分","疾病",CommonConsts.INGREDIENT,CommonConsts.DISEASE);
            relationsNameList.add(relationsName);

            ingrAndDiseaseList.forEach(etcmIngrDiseasePo -> {
                Relations relations = new Relations();
                relations.setSource(etcmIngrDiseasePo.getIngrId());
                relations.setTarget(etcmIngrDiseasePo.getDiseaseId());
                relations.setDistance(etcmIngrDiseasePo.getIngrDiseaseDistance());
                relationsList.add(relations);


                if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                    ingrNameMap.put(etcmIngrDiseasePo.getIngrId(),etcmIngrDiseasePo.getIngrEnName());
                    diseaseNameMap.put(etcmIngrDiseasePo.getDiseaseId(),etcmIngrDiseasePo.getDiseaseEnName());
                }

                if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                    ingrNameMap.put(etcmIngrDiseasePo.getIngrId(),etcmIngrDiseasePo.getIngrZhName());
                    diseaseNameMap.put(etcmIngrDiseasePo.getDiseaseId(),etcmIngrDiseasePo.getDiseaseZhName());
                }



            });
        }
        if (!CollectionUtils.isEmpty(pxAndHerbList)){
            RelationsName relationsName = getRelationsName(langCode,"Prescription","Herb","处方","中草药",CommonConsts.PX,CommonConsts.HERB);
            relationsNameList.add(relationsName);

            pxAndHerbList.forEach(etcmPxHerbPo -> {
                Relations relations = new Relations();
                relations.setSource(etcmPxHerbPo.getPxId());
                relations.setTarget(etcmPxHerbPo.getHerbId());
                relations.setDistance("0.005");
                relationsList.add(relations);


                if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                    pxNameMap.put(etcmPxHerbPo.getPxId(),etcmPxHerbPo.getPxEnName());
                    herbNameMap.put(etcmPxHerbPo.getHerbId(),etcmPxHerbPo.getHerbEnName());
                }

                if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                    pxNameMap.put(etcmPxHerbPo.getPxId(),etcmPxHerbPo.getPxZhName());
                    herbNameMap.put(etcmPxHerbPo.getHerbId(),etcmPxHerbPo.getHerbZhName());
                }


            });
        }
        if (!CollectionUtils.isEmpty(herbAndHerbList)){
            RelationsName relationsName = getRelationsName(langCode,"Herb","Herb","中草药","中草药",CommonConsts.HERB,CommonConsts.HERB);
            relationsNameList.add(relationsName);

            herbAndHerbList.forEach(etcmHerbHerbPo -> {
                Relations relations = new Relations();
                relations.setSource(etcmHerbHerbPo.getHerbCode());
                relations.setTarget(etcmHerbHerbPo.getTargetHerbCode());
                relations.setDistance(etcmHerbHerbPo.getHerbHerbDistance());
                relationsList.add(relations);


                if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                    herbNameMap.put(etcmHerbHerbPo.getHerbCode(),etcmHerbHerbPo.getHerbEnName());
                    herbNameMap.put(etcmHerbHerbPo.getTargetHerbCode(),etcmHerbHerbPo.getTargetHerbEnName());
                }

                if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                    herbNameMap.put(etcmHerbHerbPo.getHerbCode(),etcmHerbHerbPo.getHerbZhName());
                    herbNameMap.put(etcmHerbHerbPo.getTargetHerbCode(),etcmHerbHerbPo.getTargetHerbZhName());
                }


            });
        }
        if (!CollectionUtils.isEmpty(ingrAndIngrList)){
            RelationsName relationsName = getRelationsName(langCode,"Ingredient","Ingredient","成分","成分",CommonConsts.INGREDIENT,CommonConsts.INGREDIENT);
            relationsNameList.add(relationsName);

            ingrAndIngrList.forEach(etcmIngrIngrPo -> {
                Relations relations = new Relations();
                relations.setSource(etcmIngrIngrPo.getIngrCode());
                relations.setTarget(etcmIngrIngrPo.getTargetIngrCode());
                relations.setDistance(etcmIngrIngrPo.getIngrIngrDistance());
                relationsList.add(relations);



                if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                    ingrNameMap.put(etcmIngrIngrPo.getIngrCode(),etcmIngrIngrPo.getIngrEnName());
                    ingrNameMap.put(etcmIngrIngrPo.getTargetIngrCode(),etcmIngrIngrPo.getTargetIngrEnName());
                }

                if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                    ingrNameMap.put(etcmIngrIngrPo.getIngrCode(),etcmIngrIngrPo.getIngrZhName());
                    ingrNameMap.put(etcmIngrIngrPo.getTargetIngrCode(),etcmIngrIngrPo.getTargetIngrZhName());
                }





            });
        }
        if (!CollectionUtils.isEmpty(herbAndIngrList)){
            RelationsName relationsName = getRelationsName(langCode,"Herb","Ingredient","中草药","成分",CommonConsts.HERB,CommonConsts.INGREDIENT);
            relationsNameList.add(relationsName);

            herbAndIngrList.forEach(herbIngrVo -> {
                Relations relations = new Relations();
                relations.setSource(herbIngrVo.getHerbId());
                relations.setTarget(herbIngrVo.getIngrId());
                relations.setDistance(herbIngrVo.getHerbIngrDistance());
                relationsList.add(relations);


                if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                    herbNameMap.put(herbIngrVo.getHerbId(),herbIngrVo.getHerbEnName());
                    ingrNameMap.put(herbIngrVo.getIngrId(),herbIngrVo.getIngrEnName());
                }

                if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                    herbNameMap.put(herbIngrVo.getHerbId(),herbIngrVo.getHerbZhName());
                    ingrNameMap.put(herbIngrVo.getIngrId(),herbIngrVo.getIngrZhName());


                }



            });
        }


        pxNameMap.keySet().forEach(key->{
            ResolutionNames resolutionNames = new ResolutionNames();
            resolutionNames.setId(key);
            resolutionNames.setName(pxNameMap.get(key));
            resolutionNames.setCategory(CommonConsts.PX);
            resolutionNamesList.add(resolutionNames);
        });

        diseaseNameMap.keySet().forEach(key->{
            ResolutionNames resolutionNames = new ResolutionNames();
            resolutionNames.setId(key);
            resolutionNames.setName(diseaseNameMap.get(key));
            resolutionNames.setCategory(CommonConsts.DISEASE);
            resolutionNamesList.add(resolutionNames);
        });


        herbNameMap.keySet().forEach(key->{
            ResolutionNames resolutionNames = new ResolutionNames();
            resolutionNames.setId(key);
            resolutionNames.setName(herbNameMap.get(key));
            resolutionNames.setCategory(CommonConsts.HERB);
            resolutionNamesList.add(resolutionNames);
        });

        ingrNameMap.keySet().forEach(key->{
            ResolutionNames resolutionNames = new ResolutionNames();
            resolutionNames.setId(key);
            resolutionNames.setName(ingrNameMap.get(key));
            resolutionNames.setCategory(CommonConsts.INGREDIENT);
            resolutionNamesList.add(resolutionNames);
        });


        scatterDiagram.setLinks(relationsList);
        scatterDiagram.setNodeList(resolutionNamesList);
        scatterDiagram.setContractlist(relationsNameList);
        vo.setScatterDiagram(scatterDiagram);
        return vo;
    }

    @Override
    public ResultModel<PageModel<Map<String, String>>> getHerbHerbPage(HerbHerbPageReqVo reqVo) {

//        ResultModel<PxNetworkStatisticsRespVo> network = getNetwork(reqVo, false, false, false, false, true, true, true, CommonConsts.STATUS_DEL);
        ResultModel<PxNetworkStatisticsRespVo> network = getNetwork(reqVo, false, false, false, false, true, true, true, CommonConsts.STATUS_DEL);
        if (!network.isSuccess()){
            return new ResultModel<PageModel<Map<String, String>>>().failure(network.getMessage());
        }

        return new ResultModel<PageModel<Map<String, String>>>().success(network.getData().getTableList());
    }



    private static RelationsName getRelationsName(String langCode,String sourceEnName,String targetEnName,String sourceZhName,String targetZhName,int sourceCategory,int targetCategory) {
        RelationsName relationsName = new RelationsName();
        if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
            relationsName.setSourceName(sourceEnName);
            relationsName.setTargetName(targetEnName);

        }
        if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
            relationsName.setSourceName(sourceZhName);
            relationsName.setTargetName(targetZhName);

        }
        relationsName.setSourceCategory(sourceCategory);
        relationsName.setTargetCategory(targetCategory);
        return relationsName;
    }

    @Override
    public Map<String, String> getStringStringMap(String langCode, EtcmPxHerbPo etcmPxHerbPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), etcmPxHerbPo.getPxId());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmPxHerbPo.getPxEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmPxHerbPo.getPxZhName());
                    }
                    break;
                case 3:
                    map.put(etcmUiElPo.getUiElCode(), etcmPxHerbPo.getHerbId());
                    break;
                case 4:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmPxHerbPo.getHerbEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmPxHerbPo.getHerbZhName());
                    }
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), "0.005");
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(),"0.5");
                default:
            }

        }
        return map;
    }

    @Override
    public Map<String, String> getStringStringMap(String langCode, EtcmIngrDiseasePo etcmIngrDiseasePo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getIngrId());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getIngrEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getIngrZhName());
                    }
                    break;
                case 3:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getDiseaseId());
                    break;
                case 4:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getDiseaseEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getDiseaseZhName());
                    }
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getIngrDiseaseDistance());
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(),etcmIngrDiseasePo.getPValue());
                default:
            }

        }
        return map;
    }

    @Override
    public Map<String, String> getStringStringMap(String langCode, EtcmHerbDiseasePo etcmHerbDiseasePo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getHerbId());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getHerbEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getHerbZhName());
                    }
                    break;
                case 3:
                    map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getDiseaseId());
                    break;
                case 4:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getDiseaseEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getDiseaseZhName());
                    }
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getHerbDiseaseDistance());
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(),etcmHerbDiseasePo.getPValue());
                default:
            }

        }
        return map;
    }
    @Override
    public Map<String, String> getStringStringMap(String langCode, PxDiseaseRespVo pxDiseaseRespVo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), pxDiseaseRespVo.getPxId());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), pxDiseaseRespVo.getPxEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), pxDiseaseRespVo.getPxZhName());
                    }
                    break;
                case 3:
                    map.put(etcmUiElPo.getUiElCode(), pxDiseaseRespVo.getDiseaseId());
                    break;
                case 4:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), pxDiseaseRespVo.getDiseaseEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), pxDiseaseRespVo.getDiseaseZhName());
                    }
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), pxDiseaseRespVo.getPxDiseaseDistance());
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(),pxDiseaseRespVo.getPValue());
                default:
            }

        }
        return map;
    }



    @Override
    public Map<String, String> getStringStringMap(String langCode, EtcmHerbHerbPo etcmHerbHerbPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), StringUtils.isNotBlank(etcmHerbHerbPo.getHerbCode()) ? etcmHerbHerbPo.getHerbCode() : "");
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), StringUtils.isNotBlank(etcmHerbHerbPo.getHerbEnName()) ? etcmHerbHerbPo.getHerbEnName():"");
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), StringUtils.isNotBlank(etcmHerbHerbPo.getHerbZhName()) ? etcmHerbHerbPo.getHerbZhName():"");
                    }
                    break;
                case 3:
                    map.put(etcmUiElPo.getUiElCode(), StringUtils.isNotBlank(etcmHerbHerbPo.getTargetHerbCode()) ? etcmHerbHerbPo.getTargetHerbCode() : "");
                    break;
                case 4:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), StringUtils.isNotBlank(etcmHerbHerbPo.getTargetHerbEnName()) ? etcmHerbHerbPo.getTargetHerbEnName(): "");
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), StringUtils.isNotBlank(etcmHerbHerbPo.getTargetHerbZhName()) ? etcmHerbHerbPo.getTargetHerbZhName() :"");
                    }
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), StringUtils.isNotBlank(etcmHerbHerbPo.getHerbHerbDistance()) ? etcmHerbHerbPo.getHerbHerbDistance() : "");
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(),StringUtils.isNotBlank(etcmHerbHerbPo.getPValue()) ? etcmHerbHerbPo.getPValue() : "");
                default:
            }

        }
        return map;
    }



    @Override
    public Map<String, String> getStringStringMap(String langCode, EtcmIngrIngrPo etcmIngrIngrPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getIngrCode());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getIngrEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getIngrZhName());
                    }
                    break;
                case 3:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getTargetIngrCode());
                    break;
                case 4:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getTargetIngrEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getTargetIngrZhName());
                    }
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getIngrIngrDistance());
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(),etcmIngrIngrPo.getPValue());
                default:
            }

        }
        return map;
    }
    @Override
    public Map<String, String> getStringStringMap(String langCode, HerbIngrVo herbIngrVo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), herbIngrVo.getHerbId());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), herbIngrVo.getHerbEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), herbIngrVo.getHerbZhName());
                    }
                    break;
                case 3:
                    map.put(etcmUiElPo.getUiElCode(), herbIngrVo.getIngrId());
                    break;
                case 4:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), herbIngrVo.getIngrEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), herbIngrVo.getIngrZhName());
                    }
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), herbIngrVo.getHerbIngrDistance());
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(),herbIngrVo.getPValue());
                default:
            }

        }
        return map;
    }

    private List<String> getIngrStatistics(long totalNumber, Map<String, Long> map) {
        List<String> arr = new ArrayList<>();
        for (String key : map.keySet()) {
            BigDecimal totalSize = new BigDecimal(totalNumber);
            BigDecimal size = new BigDecimal(map.get(key));
            BigDecimal bigDecimal = size.divide(totalSize,2, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
            arr.add(bigDecimal.toString());
        }
        return arr;
    }

    private Map<String,String> getStatistics(long totalNumber, Map<String, Long> map) {
        Map<String,String> resMap= new HashMap<>(16);
        for (String key : map.keySet()) {
            BigDecimal totalSize = new BigDecimal(totalNumber);
            BigDecimal size = new BigDecimal(map.get(key));
            BigDecimal bigDecimal = size.divide(totalSize,2, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
            resMap.put(key,bigDecimal.toString());
        }
        return resMap;
    }

    private static Map<String, String> getStringStringMap(String langCode, EtcmExperimentalRecordsIngrPo recordsIngrPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getErId());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getErEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getErZhName());
                    }
                    break;
                case 3:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getPubchemCid());
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getMolecularFormula());
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getMolecularWeight());
                    break;
                case 7:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getConcentration());
                    break;
                case 8:
                    map.put(etcmUiElPo.getUiElCode(),recordsIngrPo.getCelllines());
                    break;
                case 9:
                    map.put(etcmUiElPo.getUiElCode(),recordsIngrPo.getOrangism());
                default:
                    map.put(UiElCodeEnums.IS_MAP.getUiElCode(),recordsIngrPo.getIsMap());
            }

        }
        return map;
    }

    private static Map<String, String> getStringStringMapDownload(String langCode, EtcmExperimentalRecordsIngrPo recordsIngrPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getErId());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getErEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getErZhName());
                    }
                    break;
                case 3:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getPubchemCid());
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getMolecularFormula());
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getMolecularWeight());
                    break;
                case 7:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getConcentration());
                    break;
                case 8:
                    map.put(etcmUiElPo.getUiElCode(),recordsIngrPo.getCelllines());
                    break;
                case 9:
                    map.put(etcmUiElPo.getUiElCode(),recordsIngrPo.getOrangism());
                default:
            }

        }
        return map;
    }
    private static Map<String, String> getStringStringMap(String langCode, EtcmIngrTargetPo etcmIngrTargetPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getTargetId());
                    break;
                case 2:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getSymbolIdHum());
                    break;
                case 3:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getIngrEnName() + "||" + etcmIngrTargetPo.getIngrId());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getIngrZhName()+ "||" + etcmIngrTargetPo.getIngrId());
                    }
                    break;
                case 4:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getHerbEnName()+ "||" + etcmIngrTargetPo.getHerbId());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getHerbZhName()+ "||" + etcmIngrTargetPo.getHerbId());
                    }
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getTypeName());
                    break;
                case 7:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getEntrezIdHum());
                    break;
                case 8:
                    map.put(etcmUiElPo.getUiElCode(),etcmIngrTargetPo.getUniprotIdHum());
                default:
            }

        }
        return map;
    }

    private static Map<String, String> getStringStringMapDownload(String langCode, EtcmIngrTargetPo etcmIngrTargetPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getTargetId());
                    break;
                case 2:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getSymbolIdHum());
                    break;
                case 3:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getIngrEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getIngrZhName());
                    }
                    break;
                case 4:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getHerbEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getHerbZhName());
                    }
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getTypeName());
                    break;
                case 7:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getEntrezIdHum());
                    break;
                case 8:
                    map.put(etcmUiElPo.getUiElCode(),etcmIngrTargetPo.getUniprotIdHum());
                default:
            }

        }
        return map;
    }
}
